So, my creation is a weather station that tells me what to wear depending on the temperature, and light up an RGB LED, and it will Pulse Red, Green, Blue or a mix of colors. I got the PWM and Pulsing working, but the LED seems to flicker then pulse. I cannot seem to figure out why.
Can you guys review my coding and watch the video, then give some suggestions.
#include <LiquidCrystal.h> // includes math and LCD libraries
#include <math.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initalizes the pins the LCD screen will use.
int Temperature = analogRead(0); //Thermistor connected to Analog "0" and the "Temperature" integer is equal to analogRead of pin A0.
int indicatorHot = 5; // Hot LED on D13
int indicatorNorm = 9; // Norm LED on D9
int indicatorCold = 6; // Cold LED on D8
double Thermister(int RawADC) // the Thermister is going to convert an integer which is the Raw ADC, some type or raw current from the Thermister
{
double Temp;
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp ); // this converts the raw crap into Kelvin...
Temp = Temp - 273.15; // Converting Kelvin into Celsius
Temp = (Temp * 9.0)/ 5.0 + 32.0; // Converting Celsius into Fahrenheit
return Temp;
}
void setup() // setup procedure runs once...actually has no purpose other than to show the faux startup screen, and run through and test the LEDs
{
pinMode(indicatorHot, OUTPUT); //defines indicator Pins as outputs
pinMode(indicatorNorm, OUTPUT);
pinMode(indicatorCold, OUTPUT);
Serial.begin(9600);
for(int fadeValue = 0; fadeValue <= 100; fadeValue +=10)
{
// sets the value (range from 0 to 100):
analogWrite(indicatorHot, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
// fade out from max to min in increments of 5 points:
}
for(int fadeValue = 0; fadeValue <= 100; fadeValue +=10)
{
// sets the value (range from 0 to 100):
analogWrite(indicatorNorm, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
// fade out from max to min in increments of 5 points:
}
for(int fadeValue = 100; fadeValue >= 0; fadeValue -=10)
{
// sets the value (range from 0 to 100):
analogWrite(indicatorHot, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
// fade out from max to min in increments of 5 points:
}
for(int fadeValue = 0; fadeValue <= 100; fadeValue +=10)
{
// sets the value (range from 0 to 100):
analogWrite(indicatorCold, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
// fade out from max to min in increments of 5 points:
}
for(int fadeValue = 100; fadeValue >= 0; fadeValue -=10)
{
// sets the value (range from 0 to 100):
analogWrite(indicatorNorm, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
// fade out from max to min in increments of 10 points:
}
for(int fadeValue = 100; fadeValue >= 0; fadeValue -=10)
{
// sets the value (range from 0 to 100):
analogWrite(indicatorCold, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
// fade out from max to min in increments of 10 points:
}
lcd.begin(16,2); // begins the LCD screen and defines the columns, rows
lcd.clear(); // clears LCD screen
lcd.cursor(); // turns cursor on and blinks to look cool
delay(100);
lcd.noCursor();
delay(100);
lcd.cursor();
delay(100);
lcd.autoscroll();
lcd.noCursor();
lcd.print("Sexy Weatherduino Station"); // displays projects name
lcd.setCursor(0,2); // moves cursor
lcd.cursor(); // blinks cursor again to simulate loading
delay(100);
lcd.noCursor();
delay(100);
lcd.cursor();
delay(100);
lcd.noCursor();
lcd.print("beginning startup"); // simulates a program loading screen type thing with dots appearing as time progresses for 3 seconds
delay(1000);
lcd.print("beginning startup.");
delay(1000);
lcd.print("beginning startup..");
delay(1000);
lcd.print("beginning startup...");
}
void loop()
{
lcd.print("Fahrenheit:"); //displays Fahrenheit so you know what the god damn numbers stand for.
lcd.print(int(Thermister(analogRead(0)))); // calls the Thermister function, which reads the voltage from "A0" and then displays its value as an integer.
if (int(Thermister(analogRead(0))) > 80) // if the temperature returned from the function is greater than 80 (in degrees) display the following
{
Serial.println(int(Thermister(analogRead(0))));
for(int fadeValue = 0; fadeValue <= 255; fadeValue +=5)
{
// sets the value (range from 0 to 255):
analogWrite(indicatorHot, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(10);
// fade out from max to min in increments of 5 points:
}
for(int fadeValue = 255; fadeValue >= 0; fadeValue -=5)
{
// sets the value (range from 0 to 255):
analogWrite(indicatorHot, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(10);
// fade out from max to min in increments of 5 points:
}
lcd.setCursor(0,2);
lcd.autoscroll();
lcd.print("its hot.");
delay(100);
lcd.print("its hot. take off your clothes.");
delay(100);
lcd.print("its hot. take off your clothes..");
delay(100);
lcd.print("its hot. take off your clothes...");
}
else if (int(Thermister(analogRead(0))) > 45) // if the temperature returned from the function is greater than 45 (in degrees) display the following
{
for(int fadeValue = 0; fadeValue <= 255; fadeValue +=5)
{
// sets the value (range from 0 to 255):
analogWrite(indicatorNorm, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(10);
// fade out from max to min in increments of 5 points:
}
for(int fadeValue = 255; fadeValue >= 0; fadeValue -=5)
{
// sets the value (range from 0 to 255):
analogWrite(indicatorNorm, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(10);
// fade out from max to min in increments of 5 points:
}
Serial.println(int(Thermister(analogRead(0))));
lcd.setCursor(0,2);
lcd.autoscroll();
lcd.print("its mild out keep your clothes on");
delay(100);
lcd.print("its mild out keep your clothes on.");
delay(100);
lcd.print("its mild out keep your clothes on..");
delay(100);
lcd.print("its mild out keep your clothes on...");
}
else if (int(Thermister(analogRead(0))) > 30) // if the temperature returned from the function is greater than 45 (in degrees) display the following
{
for(int fadeValue = 0; fadeValue <= 255; fadeValue +=5)
{
// sets the value (range from 0 to 255):
analogWrite(indicatorCold, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(10);
// fade out from max to min in increments of 5 points:
}
for(int fadeValue = 255; fadeValue >= 0; fadeValue -=5)
{
// sets the value (range from 0 to 255):
analogWrite(indicatorCold, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(10);
// fade out from max to min in increments of 5 points:
}
Serial.println(int(Thermister(analogRead(0))));
lcd.setCursor(0,2);
lcd.autoscroll();
lcd.print("its cool out, may want a sweater vest");
delay(100);
lcd.print("its cool out, may want a sweater vest.");
delay(100);
lcd.print("its cool out, may want a sweater vest..");
delay(100);
lcd.print("its cool out, may want a sweater vest...");
}
else // if the temperature returned from the function is doesnt fit the upper stuff display this
{
for(int fadeValue = 0; fadeValue <= 255; fadeValue +=5)
{
// sets the value (range from 0 to 255):
analogWrite(indicatorCold, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(10);
// fade out from max to min in increments of 5 points:
}
for(int fadeValue = 255; fadeValue >= 0; fadeValue -=5)
{
// sets the value (range from 0 to 255):
analogWrite(indicatorCold, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(10);
// fade out from max to min in increments of 5 points:
}
Serial.println(int(Thermister(analogRead(0))));
lcd.setCursor(0,2);
lcd.autoscroll();
lcd.print("its a tit bit nipply out");
delay(100);
lcd.print("its a tit bit nipply out.");
delay(100);
lcd.print("its a tit bit nipply out..");
delay(100);
lcd.print("its a tit bit nipply out...");
}
}