From 6b3b11d398cf27f46580b1b48d93aa30b22048a4 Mon Sep 17 00:00:00 2001 From: Christian Kindel Date: Sun, 29 Oct 2017 20:55:17 -0500 Subject: [PATCH] Code run at Ecofest 2017 --- GiantMeterCode/GiantMeterCode.ino | 82 +++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 GiantMeterCode/GiantMeterCode.ino diff --git a/GiantMeterCode/GiantMeterCode.ino b/GiantMeterCode/GiantMeterCode.ino new file mode 100644 index 0000000..3315e80 --- /dev/null +++ b/GiantMeterCode/GiantMeterCode.ino @@ -0,0 +1,82 @@ +int output_min=30; +int output_max=150; + +int input_min=500; +int input_max= 825; + +byte input_pin = A0; +byte output_pin = 9; +byte config_button_pin = 3; + +#define smoothing 30 +//int smoothing=30; +int buffer[smoothing]; +int bufpos = 0; +int autoconf_seconds = 20; + +void setup() { + pinMode(input_pin, INPUT); + pinMode(output_pin, OUTPUT); + digitalWrite(output_pin,0); + + Serial.begin(9600); +} + +void loop() { +// while(1){ +// SweepTest(); +// } + // AutoConfigure(); + while(1) { + RunMeter(); + } +} + +void AutoConfigure() { + unsigned long start_time = millis(); + int max_value = 0; + int min_value = 1023; + while (millis()-start_time < autoconf_seconds*1000) + { + int value = analogRead(input_pin); + if(value > max_value) + max_value = value; + if(value < min_value) + min_value = value; + } + input_min = min_value; + //input_max = max_value; +} + +void RunMeter() { + int current_value = analogRead(input_pin); + int total = 0; + bufpos = (bufpos+1)%smoothing; + buffer[bufpos]= current_value; + for(int i=0; ioutput_min; output_current--) + { + analogWrite(9,output_current); + delay(50); + } +}