6.5.09

it works... i think...

You may remember my aforementioned buzz buzz, which is a little lilypad arduino circuit with has a light sensor and some vibe boards. I wanted it to vibe when it sees a certain amount of light. After much googling and hair pulling I couldn't figure out what was wrong with my original code.

I decided to come back to it today, and try again. After another couple hours of googling I found this site which had the kind of code i was trying to make. I looked at it and made some changes to my code and now it works!


//if there is light, vibe.

int pins[] = { 9, 10,}; // an array of pin numbers
int num_pins = 6; // the number of pins (i.e. the length of the array)
int ledPin = 13; // LED is connected to digital pin 13
int sensorPin = 0; // light sensor is connected to analog pin 0
int sensorValue; // variable to store the value coming from the sensor


void setup()
{
int i;

for (i = 0; i < num_pins; i++) // the array elements are numbered from 0 to num_pins - 1
pinMode(pins[i], OUTPUT); // set each pin as an output

Serial.begin(9600); //initialize the serial port

}

void loop()
{

int i;

sensorValue = analogRead(sensorPin); // read the value from the sensor
Serial.println(sensorValue); // send that value to the computer


if (sensorValue > 450) {

digitalWrite(pins[i], HIGH);
delay(100);
}
else {
digitalWrite(pins[i], LOW);
delay(100);
}


}


It's a bit tempermental, I think it's more to do with the circuit instead of the light sensor or the code. I'm going to use the data from the light sensor to bring up a feed of where it's sunny now.

No comments: