Last active
April 27, 2017 18:19
-
-
Save ethnt/de384660da330450321e8fad81c5f729 to your computer and use it in GitHub Desktop.
Arduino project
This file contains 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 <LiquidCrystal.h> | |
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); | |
int buttonPin = 7; | |
int buttonState; | |
int buttonPresses = 0; | |
void setup() { | |
lcd.begin(16, 2); | |
lcd.setCursor(0, 0); | |
lcd.print("Temp:"); | |
lcd.setCursor(0, 1); | |
lcd.print("Light: "); | |
pinMode(buttonPin, INPUT); | |
} | |
void loop() { | |
buttonState = digitalRead(buttonPin); | |
if (buttonState == HIGH) { | |
buttonPresses = buttonPresses + 1; | |
} | |
printTemperature(analogRead(A0)); | |
printLight(analogRead(A1)); | |
delay(1000); | |
} | |
void printTemperature(int sensorValue) { | |
lcd.setCursor(7, 0); | |
double temp = (double)sensorValue / 1024; | |
temp = temp * 5; | |
temp = temp - 0.5; | |
double tempC = temp * 100; | |
double tempF = tempC * (9.0 / 5.0) + 32; | |
String output; | |
if (buttonPresses % 2 == 0) { | |
output = String(tempF) + "F"; | |
} else { | |
output = String(tempC) + "C"; | |
} | |
lcd.print(output); | |
} | |
void printLight(int sensorValue) { | |
lcd.setCursor(7, 1); | |
sensorValue = sensorValue - 165; | |
String output = String(sensorValue); | |
lcd.print(output); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment