Skip to content
Snippets Groups Projects
Select Git revision
  • f6a58f546e25eab91072a9a15f4486029001604b
  • main default protected
2 results

precipitationctl.ino

Blame
  • David Huss's avatar
    David Huss authored
    f6a58f54
    History
    precipitationctl.ino 926 B
    #include "data.h"
    
    #define SERVO_MIN 30
    #define SERVO_MAX 480
    int servoPin = 23;
    int pos = SERVO_MIN;
    
    
    int data_index = 0;
    
    void setServoNormalized(float pos) {
      pos = min(1.0f, max(0.0f, pos));
      int span = SERVO_MAX - SERVO_MIN;
      int servo_pos = SERVO_MIN + span * pos;
      analogWrite(servoPin, servo_pos);
    }
    
    void setup() {
      Serial.begin(115200);
      // put your setup code here, to run once:
      pinMode(servoPin, OUTPUT);
      analogWriteFrequency(servoPin, 50);
      analogWriteResolution(servoPin, 12);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      float datum = data[data_index];
      setServoNormalized(datum);
      Serial.print("Aktueller Wert ");
      Serial.print(datum * 67.2);
      Serial.print(" mm  --> ");
      Serial.println(datum);
      data_index++;
    
      if ( data_index >= DATA_LENGTH) {
        data_index = 0;
        Serial.println("Die daten sind durch, wir fangen wieder vorne an...");
      }
      delay(28.44*1000);
    }