I cant believe I did it! I will try to put up video of it sometime soon :)
my program is working in the elephant! It may not be the most eloquent and a real programmer would think it is messy, but it works!
and the working code is....
drum roll please...
int rcheek = 9;
int rear = 5;
int lcheek = 10;
int lear = 11;
int aluminumFoil = A5;
int brightness = 0; //how bright the led is
int fadeAmount = 5; //how many points to fade the led by
int sensorValue; //variable stores readings from the sensor
void setup() {
pinMode(rear, OUTPUT);
pinMode(rcheek, OUTPUT);
pinMode(lcheek, OUTPUT);
pinMode(lear, OUTPUT);
pinMode(aluminumFoil, INPUT); //sets aluminum foil pin to INPUT
digitalWrite(aluminumFoil, HIGH); //initializes the sensor
Serial.begin(9600); //initializes the communication
}
void loop() {
sensorValue = analogRead(aluminumFoil);
Serial.println(sensorValue);
delay(100); //delay for 1/10 of a second
if (sensorValue < 990 && sensorValue > 895) // if touching sensor
{
analogWrite(rcheek, brightness);
analogWrite (lcheek, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
}
else if (sensorValue <= 895 && sensorValue > 750)
{ digitalWrite (rcheek, LOW);
digitalWrite (lcheek, LOW);
digitalWrite (rear, HIGH);
digitalWrite (lear, HIGH);
delay (200);
digitalWrite(rear, LOW); //turn the LED off
digitalWrite(lear, LOW); //turn the LED off
delay (200);
}
else if (sensorValue <= 750)
{{
analogWrite(rcheek, brightness);
analogWrite (lcheek, brightness);
// change the brightness for next time through the loop:
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
};
{digitalWrite (rear, HIGH);
digitalWrite (lear, HIGH);
delay (200);
digitalWrite(rear, LOW); //turn the LED off
digitalWrite(lear, LOW); //turn the LED off
delay (200);
}}}
else
{
digitalWrite (rear, LOW);
digitalWrite (lear, LOW);
digitalWrite (rcheek, LOW);
digitalWrite (lcheek, LOW);
}
}
Subscribe to:
Post Comments (Atom)
3 comments:
I'm sure glad you posted the actual code. I am going to list it on e-bay in the morning!
Good job!!!!!
pretty sure that anyone who would think to make code for something like this would make it much better....
just sayin....
woah baby! good job!
Post a Comment