This exercise has given me time to recap everything I have learned so far in terms of programming and electrical wiring. I now need to think about and work on the fabrication part. I cleaned up the wires which previously were all tangled up with jumper wire kit I bought from Radioshack. It was very neat and easy to understand the wiring.
In this exercise, I used photosensor again to create different states. The photosensor responds to the amount of light present in the surrounding area. I used three LEDs (Red, Yellow, Blue) and put short straws on top of the LEDs to maximize the dynamic glow in the dark. At first I struggled with the sensor to work because I put it in wrong direction. I understood now how the breadboard works and how I should place like photosensors and resistors.
Sleep is the state when there is no light turned on. Complete darkness. Attract is when the red light glows with limited light present. When I turn the switch of a lamp on, the lamp will illuminate the room and the red Led would change to yellow and to blue very fast. This is arousal. Reward is three lights blinking simultaneously.
sourcecode language=’css’
int analogValue0 = 0;
int analogPin0 = 0;
int ledPinRed = 13;
int ledPinYellow = 11;
int ledPinGreen = 7;
void setup() {
pinMode(analogPin0, INPUT);
pinMode(ledPinRed,OUTPUT);
pinMode(ledPinYellow,OUTPUT);
pinMode(ledPinGreen,OUTPUT);
Serial.begin(9600); // Set up the serial communication.
}
void loop() {
analogValue0 = analogRead(analogPin0);
Serial.print(“Raw Sensor value: “);
Serial.println(analogValue0);
if (analogValue0 > 400) {
digitalWrite(ledPinGreen, HIGH);
}
else {
digitalWrite(ledPinGreen, LOW);
}
if (analogValue0 > 125&&analogValue0 < 400) {
digitalWrite(ledPinYellow, HIGH);
}
else {
digitalWrite(ledPinYellow, LOW);
}
if (analogValue0 < 125) {
digitalWrite(ledPinRed, HIGH);
}
else {
digitalWrite(ledPinRed, LOW);
}
}
/sourcecode
Leave a comment