include <Wire.h> อันแรกเลยครับที่เป็นสีแดงแล้วมันเขียนว่า 'include' does not name a type
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int sensor[5] = {0, 0, 0, 0, 0};
String my_sensor ;
int buzzer = 8;
void setup ( ) {
lcd.begin();
lcd.backlight();
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(buzzer, OUTPUT);
}
void loop ( ) {
sensor[0] = digitalRead(7);
sensor[1] = digitalRead(6);
sensor[2] = digitalRead(5);
sensor[3] = digitalRead(4);
sensor[4] = digitalRead(3);
my_sensor = "S = " + String(sensor[0]) + "," + String(sensor[1]) + "," + String(sensor[2]) + "," + String(sensor[3]) + "," + String(sensor[4]) + ",";
if ((sensor[0] == 0) && (sensor[1] == 0) && (sensor[2] == 0) && (sensor[3] == 0) && (sensor[4] == 0)) {
lcd.setCursor(0, 0);
lcd.print(my_sensor);
lcd.setCursor(0, 1);
lcd.print("NORMAL ");
}
else {
lcd.setCursor(0, 0);
lcd.print(my_sensor);
lcd.setCursor(0, 1);
lcd.print("FIRE ALARM");
buzzer_on();
}
delay(10);
}
void buzzer_on()
{ unsigned char i, j;
{ for (i = 0; i < 80; i++)
{ digitalWrite(buzzer, HIGH);
delay(1);//delay1ms
digitalWrite(buzzer, LOW);
delay(1);//ms delay
}
for (i = 0; i < 100; i++)
{
digitalWrite(buzzer, HIGH);
digitalWrite(buzzer, LOW);
delay(2);
}
}
}
'include' does not name a type แก้ยังไงหรอครับ?
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
int sensor[5] = {0, 0, 0, 0, 0};
String my_sensor ;
int buzzer = 8;
void setup ( ) {
lcd.begin();
lcd.backlight();
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(buzzer, OUTPUT);
}
void loop ( ) {
sensor[0] = digitalRead(7);
sensor[1] = digitalRead(6);
sensor[2] = digitalRead(5);
sensor[3] = digitalRead(4);
sensor[4] = digitalRead(3);
my_sensor = "S = " + String(sensor[0]) + "," + String(sensor[1]) + "," + String(sensor[2]) + "," + String(sensor[3]) + "," + String(sensor[4]) + ",";
if ((sensor[0] == 0) && (sensor[1] == 0) && (sensor[2] == 0) && (sensor[3] == 0) && (sensor[4] == 0)) {
lcd.setCursor(0, 0);
lcd.print(my_sensor);
lcd.setCursor(0, 1);
lcd.print("NORMAL ");
}
else {
lcd.setCursor(0, 0);
lcd.print(my_sensor);
lcd.setCursor(0, 1);
lcd.print("FIRE ALARM");
buzzer_on();
}
delay(10);
}
void buzzer_on()
{ unsigned char i, j;
{ for (i = 0; i < 80; i++)
{ digitalWrite(buzzer, HIGH);
delay(1);//delay1ms
digitalWrite(buzzer, LOW);
delay(1);//ms delay
}
for (i = 0; i < 100; i++)
{
digitalWrite(buzzer, HIGH);
digitalWrite(buzzer, LOW);
delay(2);
}
}
}