Created
January 15, 2012 14:18
-
-
Save julsam/1615984 to your computer and use it in GitHub Desktop.
Temperature sensor + LED display
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
int pin = 0; // analog pin | |
int temp = 0; // temperature variable | |
int samples[8]; | |
int ledPins[] = { 2, 3, 4, 5, 6, 7 }; | |
int binaries[] = { B00100000, B00010000, B00001000, B00000100, B00000010, B00000001}; // control bits | |
const int ledCount = 6; | |
void setup() | |
{ | |
Serial.begin(9600); | |
for (int thisLed = 0; thisLed < ledCount; thisLed++) { | |
pinMode(ledPins[thisLed], OUTPUT); | |
} | |
} | |
void loop() | |
{ | |
// gets 8 samples of temperature | |
for (int i = 0; i <= 7; i++) | |
{ | |
samples[i] = (5.0 * analogRead(pin) * 100.0) / 1024.0; | |
temp = temp + samples[i]; | |
delay(1000); | |
} | |
temp = temp / 8.0; // 8 = number of samples | |
Serial.print(temp, DEC); | |
Serial.println(" Celsius "); | |
for (int thisLed = 0; thisLed < ledCount; thisLed++) { | |
if ((temp & binaries[thisLed]) > 0) { | |
digitalWrite(ledPins[thisLed], HIGH); | |
} else { | |
digitalWrite(ledPins[thisLed], LOW); | |
} | |
} | |
temp = 0; | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment