Responsive Wearable

CODE:

int ledPin = 11; // LED connected to digital pin 13
int ledPin1 = 10;
int ledPin2 = 9;
int ledPin3 = 6;
int ledPin4 = 5;

int sensorPin = A2; // light sensor is connected to analog pin 0
int sensorValue = A2; // variable to store the value coming from the sensor
int sensorFrequency = 100; // number of milliseconds between sensor readings

int lightThreshold = 10; // threshold below which light turns on

void setup()
{
pinMode(ledPin, OUTPUT); // sets the ledPin to be an output

pinMode(ledPin1, OUTPUT); // sets the ledPin to be an output
pinMode(ledPin2, OUTPUT); // sets the ledPin to be an output
pinMode(ledPin3, OUTPUT); // sets the ledPin to be an output
pinMode(ledPin4, OUTPUT); // sets the ledPin to be an output

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

}

void loop() // run over and over again
{
sensorValue = analogRead(sensorPin); // read the value from the sensor
Serial.println(sensorValue); // send that value to the computer

/* Turn on the LEDs if the light sensor drops below threshold */
if (sensorValue <= lightThreshold){
digitalWrite(ledPin, HIGH); // turn the LED on

digitalWrite(ledPin1, HIGH); // turn the LED on
digitalWrite(ledPin2, HIGH); // turn the LED on
digitalWrite(ledPin3, HIGH); // turn the LED on
digitalWrite(ledPin4, HIGH); // turn the LED on
}
else // turn the LEDs off
{
digitalWrite(ledPin, LOW); // turn the LED off

digitalWrite(ledPin1, LOW); // turn the LED off
digitalWrite(ledPin2, LOW); // turn the LED off
digitalWrite(ledPin3, LOW); // turn the LED off
digitalWrite(ledPin4, LOW); // turn the LED off
}

/* Delay for defined delay period */
delay(sensorFrequency);
}

Comments are closed.