amateur at this programming trying to build a weather station got a code off the net and get a pong error code and cant see where i have gone wrong can anyone help please ???
ive highlighted which bit has gone wrong can someone help.
#include <dht11.h>
#include <LiquidCrystal.h>
//initialize DHT11
dht11 DHT11;
// initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//pin declaration
int lightPin = A0;
int dhtPin = A1;
int buttonPin = 7;
unsigned long cur = 0;
unsigned long measurementFrequency = 1000;
unsigned long lastMeasurement = 0;
int measurementValue = 0;
int lastButtonState = LOW;
unsigned long lastDebounce = 0;
unsigned long buttonDebounceDelay = 250;
int currMode = 0;
boolean modeChanged = false;
boolean isPing = false;
unsigned long lastPing = 0;
unsigned long pingDelay = 250;
void setup() {
//debug
//Serial.begin(9600);
//setup LCD
lcd.begin(16,2);
//print welcome text
lcd.setCursor(3,0);
lcd.print("Welcome to");
lcd.setCursor(2,1);
lcd.print("Electronics!");
delay(3000);
lcd.clear();
}
void loop()
{
//record current time in milliseconds
cur = millis();
//see if we need to measure
if ((cur - lastMeasurement > measurementFrequency) || modeChanged) {
//control members
lastMeasurement = cur;
lastPing = cur;
modeChanged = false;
//do the work
measureAndDisplay();
//make the ping (blink an asterisk)
ping();
}
{
//check if blinking
[glow=yellow,2,300][b]if (isPing && cur - lastPing > pingDelay) pong(); [/b] [/glow]
//monitor if button pressed
int currentButtonState = digitalRead(buttonPin);
if ((currentButtonState != lastButtonState) && (currentButtonState == HIGH) && (cur - lastDebounce > buttonDebounceDelay))
}
{
lastDebounce = cur;
if (currMode == 2) currMode = 0;
else currMode = currMode + 1;
modeChanged = true;
}
//debug
//Serial.println(currentButtonState);
}
void measureAndDisplay() {
//clear the display
lcd.clear();
switch (currMode) {
//0: temperature - read DHT11.temperature and write it out
case 0:
DHT11.read(dhtPin);
measurementValue = DHT11.temperature;
lcd.setCursor(2,0);
lcd.print("Temperature:");
lcd.setCursor(2,1);
lcd.print(measurementValue);
lcd.print(char(223));
lcd.print("C - ");
int toFarenheit;
toFarenheit = (measurementValue * 1.8 + 32);
//for our American friends
lcd.print(toFarenheit);
lcd.print(char(223));
lcd.print("F");
break;
case 1:
//1: humidity - read DHT11.humidity and write it out in %
measurementValue = DHT11.humidity;
lcd.setCursor(4,0);
lcd.print("Humidity");
lcd.setCursor(7,1);
lcd.print(measurementValue);
lcd.print("%");
break;
case 2:
//2: light intensity - read the light sensor and output the value in %.
//This can be converted into Lux, but I believe this setup is not precise enough.
measurementValue = analogRead(lightPin);
measurementValue = map(measurementValue, 0, 1023, 100, 0);
lcd.setCursor(0,0);
lcd.print("Light Intensity");
lcd.setCursor(7,1);
lcd.print(measurementValue);
lcd.print("%");
break;
}
}
//show asterisk
void ping()
{
lcd.setCursor(15,1);
lcd.print("*");
isPing = true;
//debug
//Serial.println("Ping");
}
//clear asteriskvoid pong()
{
lcd.setCursor(15,1);
lcd.print(" ");
isPing = false;
//debug
//Serial.println("Pong");
}