All pastes #2108455 Raw Edit

Someone

public c v1 · immutable
#2108455 ·published 2012-02-01 01:38 UTC
rendered paste body
const int firstPin = 2;const int ledCount = 10;const int lastPin =  firstPin + ledCount;const int sampleCount = 25;int samples[sampleCount];      int index = 0;                  int total = 0;     int sample = 0;int inputPin = A0;void setup() {  Serial.begin(9600);  for(int pin = firstPin; pin <= lastPin; pin++)    pinMode(pin, OUTPUT);  for (int s = 0; s < sampleCount; s++)    samples[s] = 0;}void loop() {  total = total - samples[index];           samples[index] = analogRead(inputPin);   total = total + samples[index];         index = index + 1;                      if (index >= sampleCount)                  index = 0;                             // average the samples  sample = min(total / sampleCount, 50);           Serial.println(sample);  int leds = sample / 5;  for(int i = 0; i <= leds; i++)    digitalWrite(i + firstPin, HIGH);  for(int i = leds + 1; i <= lastPin; i++)    digitalWrite(i + firstPin, LOW);}