Skip to content

Instantly share code, notes, and snippets.

@YitziG
Last active March 12, 2020 13:32
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 YitziG/26dea2c4b5e55615ab1008f63618b8de to your computer and use it in GitHub Desktop.
Save YitziG/26dea2c4b5e55615ab1008f63618b8de to your computer and use it in GitHub Desktop.
#include <FastLED.h>
#define NUM_LEDS 10
#define DATA_PIN 2
CRGB leds[NUM_LEDS];
void setup() {
Serial.begin(9600);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}
void loop() {
unsigned int ADC_Value = analogRead(A3);
float temp = ((double)ADC_Value * 450 / 614.4 - 70);
displayTemp(temp);
Serial.print(temp);
Serial.println("\u2103");//Printed temperature value
delay(10);
clearLeds();
}
void clearLeds(){
for(int i = 0; i < NUM_LEDS; i++){
leds[i] = CRGB::Black;
}
}
void displayTemp(float temp) {
if (temp > 25) {
leds[0] = CRGB::Blue;
}
if (temp > 30) {
leds[1] = CRGB::Blue;
}
if (temp > 37) {
leds[2] = CRGB::Green;
}
if (temp > 39) {
leds[3] = CRGB::Green;
}
if (temp > 41) {
leds[4] = CRGB::Yellow;
}
if (temp > 43) {
leds[5] = CRGB::Yellow;
}
if (temp > 45) {
leds[6] = CRGB::Orange;
}
if (temp > 47) {
leds[7] = CRGB::Orange;
}
if (temp > 49) {
leds[8] = CRGB::Red;
}
if (temp > 50) {
leds[9] = CRGB::Red;
}
FastLED.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment