Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(9, 8, 7, 6, 5, 4);
- int buttState;
- int buttNum = 0;
- int greenPin = 11;
- int redPin = 12;
- int bluePin = 13;
- int buttPin = 2;
- int tempPin = 0;
- float tempC;
- int tempF;
- float reading;
- float voltage;
- char firstLine[16]; //Potential problem area
- char secondLine[16];
- void setup()
- {
- Serial.begin(9600);
- lcd.begin(16, 2);
- pinMode(greenPin, OUTPUT);
- pinMode(redPin, OUTPUT);
- pinMode(bluePin, OUTPUT);
- pinMode(buttPin, INPUT);
- pinMode(tempPin, INPUT);
- Serial.println("1st Line: "); //Potential problem area
- while (Serial.available() == 0);
- firstLine[16] = Serial.read();
- Serial.println(firstLine);
- lcd.setCursor(0, 0);
- lcd.print(firstLine);
- Serial.println("2nd Line: "); //Potential problem area
- secondLine[16] = Serial.read();
- while (Serial.available() == 0);
- Serial.println(secondLine);
- lcd.setCursor(0, 1);
- lcd.print(secondLine);
- }
- int readTemp()
- {
- reading = analogRead(tempPin);
- voltage = reading * 5.0;
- voltage /= 1024.0;
- tempC = (voltage - 0.5) * 100 ;
- tempF = (tempC * 9.0 / 5.0) + 32.0;
- Serial.print(tempF); Serial.println(" degrees F");
- lcd.setCursor(13, 0);
- lcd.print(tempF);
- lcd.print("F");
- }
- void loop()
- {
- buttState = digitalRead(buttPin);
- readTemp();
- if (buttState == LOW)
- {
- buttNum++;
- }
- if (buttNum > 3)
- {
- buttNum = 0;
- }
- if (buttNum == 1)
- {
- digitalWrite(greenPin, LOW);
- }
- else
- {
- digitalWrite(greenPin, HIGH);
- }
- if (buttNum == 2)
- {
- digitalWrite(redPin, LOW);
- }
- else
- {
- digitalWrite(redPin, HIGH);
- }
- if (buttNum == 3)
- {
- digitalWrite(bluePin, LOW);
- }
- else
- {
- digitalWrite(bluePin, HIGH);
- }
- Serial.println(firstLine);
- Serial.println(secondLine);
- delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment