Skip to content
Snippets Groups Projects
Select Git revision
  • a53f6bbd69e7cfc395f9dbfde0059177e69e4146
  • master default protected
  • experimental
3 results

Pillow 1.3DS

Blame
  • precipitationctl.ino 2.65 KiB
    #include "data.h"
    #include <Ticker.h>
    #include <ESP32Servo.h> 
    #define SERVO_MIN 0
    #define SERVO_MAX 180
    #define ADC_MAX 4096
    #define INTERVAL 5
    // 28.44
    
    int servoPin = 23;
    int pos = SERVO_MIN;
    
    Servo servo;
    
    int data_index = 23;
    double ptarget = 0.0f;
    double target = 0.0f;
    double current = 0.0f;
    double blend = 0.0f;
    
    Ticker ticker;
    
    double lerp(double a, double b, double t) {
      t = max(0.0, min(1.0, t));
      return a + t * (b - a);
    }
    
    void setServoNormalized(double pos) {
      pos = min(1.0, max(0.0, pos));
      // 
      pos = sqrt(pos);
      int span = abs(SERVO_MAX - SERVO_MIN);
      int servo_pos = SERVO_MIN + span * pos;
      // Serial.print(" --> ");
      // Serial.print(pos);
      // Serial.print(" --> ");
      // Serial.println(servo_pos);
      Serial.print(SERVO_MIN); // To freeze the lower limit
      Serial.print(" ");
      Serial.print(SERVO_MAX); // To freeze the upper limit
      Serial.print(" ");
      Serial.println(servo_pos);
      servo.write(servo_pos);
    }
    
    void setNewTarget() {
      ptarget = target;
      target = data[data_index];
      current = target;
      // Serial.print("New Target is [");
      // Serial.print(data_index);
      // Serial.print("]: ");
      // Serial.print(target);
    
      data_index++;
    
      // Reset index when longer than the data (loop over)
      if (data_index >= DATA_LENGTH) {
        data_index = 0;
        Serial.println("Die daten sind durch, wir fangen wieder vorne an...");
      }
    }
    
    float testval = 0.0f;
    float increment = 0.01f;
    
    void setup() {
      Serial.begin(115200);
    
      // Allow allocation of all timers