Probably full of typo's...
Code:
unsigned values[8];
boolean firstRun=true;
unsigned j, tally;
int led12 = 8;
int led13 = 9;
void setup()
{
// Serial.begin(9800);
// Serial.println("Serial Started w00t");
pinMode(led12, OUTPUT);
pinMode(led13, OUTPUT);
}
/*
* define the switching Voltage levels for up and down
*/
#define UP 115.5
#define DOWN 118.5
/*
* Without the Voltage divider your ADC reads 50*5 Volts full scale
* So the tally ADC resolution is 50*5/1024/8
*/
#define resADC 0.0305
void loop()
{
unsigned tip = (unsigned)analogRead(0);
if(tip > 57) // 80 corrected for no scaling resistors
{
if(firstRun) // First time around, fill the array
{
for(int i = 0; i < 8; i++)
values[i] = tip;
tally = tip * 8; // and save the array tally
firstRun = false; // only do this bit once
}
if(++j > 7) // wind on array pointer
j=0; // j doesn't need to be initialised if unsigned
tally -= values[j]; // subtract old value from tally
tally += tip; // add new value into tally
values[j] = tip; // save new value
if(tally > (unsigned)(DOWN/resADC))
{
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
}
else if(tally < (unsigned)(UP/resADC))
{
digitalWrite(led12, HIGH);
digitalWrite(led13, LOW);
}
else
{
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
}
}
else
{
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
}
}