My code is coming up with a error saying 'expected initializer before 'void''
I'm fairly new to C++ and was wondering if someone could help me out with this?
Here is my Code
int temp //A0 producing 4 volts #define start_button 2 // #define any text saying start_button will be replaced with (port)2 #define LED1 3 // #define any text saying LED1 will be replaced with (port)3 #define heater_element 4 // #define any text saying heater_element will be replaced with (port)4 #define LED2 5 // #define any text saying LED2 will be replaced with (port)5 #define LED3 6 // #define any text saying LED3 will be replaced with (port)6 #define piezo_buzzer 7 // #define any text saying piezo_buzzer will be replaced with (port)7
void setup()
{
pinMode(LED1,OUTPUT); //listing all pin outputs and speed of communication
Serial.begin(9600);
pinMode(heater_element,OUTPUT);
Serial.begin(9600);
pinMode(LED2,OUTPUT);
Serial.begin(9600);
pinMode(LED3,OUTPUT);
Serial.begin(9600);
pinMode(piezo_buzzer,OUTPUT);
Serial.begin(9600);
}
void loop()
{
digitalRead(start_button,HIGH) //starting machine
{
digitalWrite(LED1,HIGH); //turning on 'started' LED
Serial.println("Started cooking process");
}
}
int temp //A0 producing 4 volts
#define start_button 2 // #define any text saying start_button will be replaced with (port)2
#define LED1 3 // #define any text saying LED1 will be replaced with (port)3
#define heater_element 4 // #define any text saying heater_element will be replaced with (port)4
#define LED2 5 // #define any text saying LED2 will be replaced with (port)5
#define LED3 6 // #define any text saying LED3 will be replaced with (port)6
#define piezo_buzzer 7 // #define any text saying piezo_buzzer will be replaced with (port)7
void setup()
{
// initialize serial communication:
Serial.begin(9600);
// initialize pins:
pinMode(LED1,OUTPUT);
pinMode(heater_element,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(piezo_buzzer,OUTPUT);
}
void loop()
{
if digitalRead(start_button==HIGH) //starting machine
{
digitalWrite (LED1,HIGH); //turning on 'started' LED
Serial.println("Started cooking process");
}
}
Arduino: 1.6.7 (Windows 10), Board: "Arduino/Genuino Uno"
Log_book_activity:20: error: expected initializer before 'void'
void loop()
^
\\nasstudusers\4$\N0616240\My Documents\Arduino\Log_book_activity\Log_book_activity.ino: In function 'void loop()':
Log_book_activity:22: error: expected '(' before 'digitalRead'
if digitalRead(start_button==HIGH) //starting machine
^
exit status 1
expected initializer before 'void'
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
and here is the corrections on the code(apologises for not seeing your original message):
int temp; //A0 producing 4V
#define start_button 2 // #define any text saying start_button will be replaced with (port)2
#define LED1 3 // #define any text saying LED1 will be replaced with (port)3
#define heater_element 4 // #define any text saying heater_element will be replaced with (port)4
#define LED2 5 // #define any text saying LED2 will be replaced with (port)5
#define LED3 6 // #define any text saying LED3 will be replaced with (port)6
#define piezo_buzzer 7 // #define any text saying piezo_buzzer will be replaced with (port)7
void setup()
{
// initialize serial communication:
Serial.begin(9600);
// initialize pins:
pinMode(LED1,OUTPUT);
pinMode(heater_element,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(piezo_buzzer,OUTPUT);
}
void loop()
{
if digitalRead(start_button==HIGH) //starting machine
{
digitalWrite (LED1,HIGH); //turning on 'started' LED
Serial.println("Started cooking process");
}
}
I've sorted that issue out now but am now having another problem! I've created a nested loop and I want it to break that loop once 10 minutes has elapsed! Here is my code:
int temp; //A0 producing 4V
#define start_button 2 // #define any text saying start_button will be replaced with (port)2
#define LED1 3 // #define any text saying LED1 will be replaced with (port)3
#define heater_element 4 // #define any text saying heater_element will be replaced with (port)4
#define LED2 5 // #define any text saying LED2 will be replaced with (port)5
#define LED3 6 // #define any text saying LED3 will be replaced with (port)6
#define piezo_buzzer 7 // #define any text saying piezo_buzzer will be replaced with (port)7
void setup()
{
// initialize serial communication:
Serial.begin(9600);
// initialize pins:
pinMode(LED1,OUTPUT);
pinMode(heater_element,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(piezo_buzzer,OUTPUT);
}
void loop()
{
if (digitalRead(start_button)==HIGH) //starting machine
{
digitalWrite (LED1,HIGH); //turning on 'started' LED
Serial.println("Started cooking process");
delay(5000); //delay for 5 seconds
}
if (analogRead(temp)<=4.5)
{
digitalWrite (heater_element,HIGH); //turing on heater
digitalWrite (LED2,HIGH); //turning on 'Boiling' LED
Serial.println("Started to boil");
delay(5000);
}
while (analogRead(temp)>4.5)
{
digitalWrite (heater_element,LOW); //turning off heating element
Serial.println("Water Boiled");
}
do
{
if (analogRead(temp)>4.5)
{
break;
}
else
{
digitalWrite (heater_element,HIGH);
delay(10000);
digitalWrite (heater_element,LOW);
delay(50000);
}
}
while(delay(600000));
}
I'm glad you got that working!
I'm happy to help but you probably need to start a new thread with the new issue and mark this one as complete.
That way everyone can pitch in! I'll keep an eye out for it.