Skip to content

Instantly share code, notes, and snippets.

@commak
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save commak/d423aa46e710a49dc803 to your computer and use it in GitHub Desktop.
Save commak/d423aa46e710a49dc803 to your computer and use it in GitHub Desktop.
LilyLilyUpdated
//Kama Kaczmarczyk #2483626
//GDES3B16 Kate Hartman
//Sensitive Wearable
// Button with LED
int ledPin = 6; // LED is connected to digital pin 6
int switchPin = 5; // button is connected to digital pin 5
int switchValue; // a variable to keep track of when switch is pressed
//Temperature Sensor
float supplyVoltage = 3.7; // Voltage
int tempSensorPin = A3; // Temperature Sensor is connected to pin A3
int tempSensorValue = 0;
int threshold1 = 8; // Value for readings
float tempSensorVoltage;
//Light sensor
int lightSensorValue = 0;
int lightSensorPin = A2; //Light sensor is connected to pin A2
int threshold2 = 100; // Value for readings
//RGB light
int greenLEDPin =11; // LED connected to digital pin 11
int blueLEDPin = 10; // LED connected to digital pin 10
int blueValue = 0; // value to write to the red LED
int greenValue = 0; // value to write to the green LED
void setup()
{ pinMode(ledPin, OUTPUT); // sets the ledPin to be an output
pinMode(switchPin, INPUT); // sets the switchPin to be an input
digitalWrite(switchPin, HIGH); // sets the default (unpressed) state of switchPin to HIGH
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop()
{
switchValue = digitalRead(switchPin);
if (switchValue == LOW) { // if the switch is pressed then,
digitalWrite(ledPin, HIGH); // turn the LED on
}
else {
digitalWrite(ledPin, LOW); // turn the LED off
}
// read the temperature sensor value
tempSensorValue = analogRead(tempSensorPin);
// convert the reading to voltage based off the reference voltage
float tempSensorVoltage = (tempSensorValue * supplyVoltage)/1024.0;
// convert the reading to Celsius
// converting from 10 mv per degree with 500 mV offset
float temperatureC = (tempSensorVoltage - 0.5) * 100;
// to degrees ((tempSensorVoltage - 500mV) times 100)
// print in Celsius
Serial.print("Degrees C: ");
Serial.print(temperatureC);
// if the value is greater than threshold #1
if(temperatureC<threshold1){
Serial.println("cold");
}
else{ // otherwise
Serial.println("warm");
}
delay(100);
// read the light sensor pin and store value in a variable:
lightSensorValue = analogRead(lightSensorPin);
// print the light sensor value
Serial.print("Light Sensor Value: ");
Serial.print(lightSensorValue);
// get ready to print light level
Serial.print(", Colour: ");
// if the value is greater than threshold #1
if(lightSensorValue>threshold2){
Serial.println("WHITE");
}
// otherwise
else{
Serial.println("BLACK");
}
// delay between readings:
delay(100);
lightSensorValue =
analogRead(lightSensorPin);
Serial.println(lightSensorValue);
delay(100);
pinMode(blueLEDPin,OUTPUT);
if (lightSensorValue < treshold2)
{
pinMode(greenLEDPin,HIGH);
}
else {
pinMode(greenLEDPin, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment