Winbond with Arduino
Currently, it plays three songs and forwards every time it detects a presence
Images
http://picasaweb.google.com/s/c/bin/slideshow.swf
—
Code
I started off with Matt’s code for the range finder–
#define NUMREADINGS 10
int readings[NUMREADINGS]; // the readings from the analog input
int index = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
int play = 9; // which light connected to digital pin 9
// int stop = 10;
int fwd = 11;
int pValue = 0; // variable to keep the actual value
// int sValue = 1; // variable to keep the actual value
int fValue = 1; // variable to keep the actual value
int rangeFinder = 5;
int closeValue = 0;
void setup()
{
Serial.begin(9600); // setup serial
for (int i = 0; i < NUMREADINGS; i++)
readings[i] = 0; // initialize all the readings to 0
}
void loop() {
/* total -= readings[index]; // subtract the last reading
readings[index] =analogRead(rangeFinder) ; // read from the sensor
total += readings[index]; // add the reading to the total
index = (index + 1); // advance to the next index
if (index >= NUMREADINGS) // if we’re at the end of the array…
index = 0; // …wrap around to the beginning
average = total / NUMREADINGS; // calculate the average
// send it to the computer (as ASCII digits)
closeValue = average;
*/
Serial.println(analogRead(rangeFinder));
if(analogRead(rangeFinder) > 300) {
// pValue = 1;
// sValue = 1;
fValue = 0;
pValue = 1;
}
else{
fValue = 1;
pValue = 0;
}
analogWrite(play, pValue);
// analogWrite(stop, sValue);
analogWrite(fwd, fValue);
/* Serial.println("—-");
Serial.println(pValue);
Serial.println(sValue);
Serial.println(fValue);
Serial.println("—-");*/
}
Reply