After a long fight with win bound chip and arduino and bubbles..., I finally heard it quack!
Quack! from Hsiang Ju Hung on Vimeo.
Here's the code:
// Input settings
int analogPin = 3; // ir sensor connected to analog pin 3
int val = 0; // variable to store the read value
// Digital pin settings
int aOut = 9; // Play pin connected to digital pin 9
// Variables
int aVal = 0; // Variables to store the input from the ir sensor
int DEBUG = 1; // Set to 1 to turn on debugging output
int average[100]; // Averaging Code setting
byte counter = 0;
void setup()
{
pinMode(aOut, OUTPUT); // sets the pin as output
if (DEBUG) {
Serial.begin(9600); // Open serial communication for reporting
}
}
//Main program
void loop(){
val = analogRead(analogPin);
//Averaging Code start
average[counter] = val;
byte c;
int total = 0;
for(c = 0;c<100;c++){
total += average[c];
}
int averaged = total / 100;
Serial.println(averaged);
counter = (counter + 1) % 100; //Averaging Code. modified from Dave Millis example
if(val < 300){
analogWrite(aOut, 0);
delay(1500);
analogWrite(aOut, 255);
delay(100);
}
else{
analogWrite(aOut, 255);
}
if (DEBUG) { // if we want to read the output
DEBUG+=1;
if(DEBUG>100){ //print every hunderd loops
DEBUG = 1; // reset the counter
Serial.print(val);
}}
}
And here is the new win bound recorder which is smaller, more solid, and works as well as the old one. It sounds actually better because I got a bigger speaker for it.
Comments
You can follow this conversation by subscribing to the comment feed for this post.