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);
}
}
Thursday, February 7, 2013
Wednesday, February 6, 2013
Welcome to my most recent headache...
why yes.... that is written code...
why no....i do not understand it....
why yes... i do have to keep writing it. I need help!
Subscribe to:
Posts (Atom)