Created
October 18, 2014 14:24
-
-
Save T-Spoon/c63bf17c87f614564f8d to your computer and use it in GitHub Desktop.
Intel Edison Temperature & LED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include <rgb_lcd.h> | |
#include <math.h> | |
rgb_lcd lcd; | |
const int colorR = 255; | |
const int colorG = 0; | |
const int colorB = 0; | |
const int PIN_LED = 13; | |
const int PIN_TOUCH = 4; | |
int tempRead; | |
float temperature; | |
int B = 3975; | |
float resistance; | |
void setup() { | |
// initialize the digital pin as an output. | |
pinMode(PIN_LED, OUTPUT); | |
pinMode(PIN_TOUCH, INPUT); | |
Serial.begin(9600); | |
// set up the LCD's number of columns and rows: | |
lcd.begin(16, 2); | |
lcd.setRGB(colorR, colorG, colorB); | |
// Print a message to the LCD. | |
lcd.print("hello, world!"); | |
delay(1000); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
//digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) | |
//delay(100); // wait for a second | |
//digitalWrite(led, LOW); // turn the LED off by making the voltage LOW | |
//delay(100); // wait for a second | |
if (isTouchPressed()) { | |
digitalWrite(PIN_LED, HIGH); | |
} else { | |
digitalWrite(PIN_LED, LOW); | |
} | |
// set the cursor to column 0, line 1 | |
// (note: line 1 is the second row, since counting begins with 0): | |
//lcd.setCursor(0, 1); | |
// print the number of seconds since reset: | |
//lcd.print(millis()/1000); | |
delay(100); | |
tempRead = analogRead(0); | |
resistance=(float)(1023-tempRead)*10000/tempRead; //get the resistance of the sensor; | |
temperature = 1 / (log(resistance/10000)/B+1/298.15)-273.15;//convert to temperature via datasheet ; | |
delay(1000); | |
lcd.setCursor(0, 1); | |
char buffer[50]; | |
sprintf(buffer, "Temp is: %f", temperature); | |
lcd.print(buffer); | |
} | |
boolean isTouchPressed() { | |
int sensorValue = digitalRead(PIN_TOUCH); | |
return sensorValue > 0.5; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment