I am working on implementing multiple modes of a project for my engineering class. Whenever I compile, I get this error message:
Arduino: 1.8.9 (Windows Store 1.8.21.0) (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
SlaveBT_test:15:11: error: two or more data types in declaration of 'LEDpin'
const int LEDpin = 8; //LED assigned to digital pin 8
^
D:\Users\austi\Documents\College shiz\FSE100\Arduino Stuff\SlaveBT_test\SlaveBT_test.ino: In function 'void setup()':
SlaveBT_test:25:11: error: 'LEDpin' was not declared in this scope
pinMode(LEDpin, OUTPUT); //Define LEDpin a an output
^
D:\Users\austi\Documents\College shiz\FSE100\Arduino Stuff\SlaveBT_test\SlaveBT_test.ino: In function 'void loop()':
SlaveBT_test:32:16: error: 'LEDpin' was not declared in this scope
digitalWrite(LEDpin, LOW); //start with the LED off
^
exit status 1
two or more data types in declaration of 'LEDpin'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
I am confused, as I am pretty sure I have only used LEDpin in the areas specified in the error message, and haven't declared it as some other variable.
Here is the code:
/*
== SLAVE CODE ==
*/
#include <SoftwareSerial.h>
SoftwareSerial BTserial (2, 3); // RX | TX
enum MODE {
OFF_MODE, // Neither the light or buzzer works 0
LIGHT_MODE, // Only the LED works 1
SOUND_MODE, // Only the buzzer works 2
BOTH_MODE, // Both work 3
MAX_MODES // 4
}
const int LEDpin = 8; //LED assigned to digital pin 8
const int buzzer = 5; //Buzzer assigned to digital pin 5
const int button = 10; //Button assigned to digital pin 10
int sound = 1500; //Frequency for buzzer
int buttonState = 0;
int funcState = 0;
void setup() {
pinMode(LEDpin, OUTPUT); //Define LEDpin a an output
pinMode(buzzer, OUTPUT); //Define buzzer as and output
pinMode(button, INPUT); //define button as an input
Serial.begin(9600); //Start serial communication
BTserial.begin(38400); // Default communication rate of the Bluetooth module
}
void loop() {
digitalWrite(LEDpin, LOW); //start with the LED off
noTone(buzzer); //start with the buzzer off
buttonPressed(); //detect the push of the button
switch (funcState) {
case OFF_MODE:
break;
case LIGHT_MODE:
if (BTserial.available()) { // Checks whether data is comming from the serial port
char c = BTserial.read(); //assigns value sent from other BT module to C
Serial.print(c); //displays the value to the serial monitor
if (c == '1') {
digitalWrite(LEDpin, HIGH);
noTone(buzzer);
}
else {
digitalWrite(LEDpin, LOW);
noTone(buzzer);
}
}
break;
case SOUND_MODE:
if (BTserial.available()) { // Checks whether data is comming from the serial port
char c = BTserial.read();
Serial.write(c);
if (c == '1') {
digitalWrite(LEDpin, LOW);
tone(buzzer, sound);
}
else {
digitalWrite(LEDpin, LOW);
noTone(buzzer);
}
}
break;
case BOTH_MODE:
if (BTserial.available()) { // Checks whether data is comming from the serial port
char c = BTserial.read();
Serial.write(c);
if (c == '1') {
digitalWrite(LEDpin, HIGH);
tone(buzzer, sound);
}
else {
digitalWrite(LEDpin, LOW);
noTone(buzzer);
}
}
break;
}
}
void buttonPressed() {
buttonState = pulseIn(button, HIGH); //detect the button press
if (buttonState > 25) {
funcState++;
}
funcState = funcState % MAX_MODES;
}
I am using an enum data type, which I have never used before and have just started teaching myself about, specifically for this project. Any help in identifying where my error is or anything is greatly appreciated.
What the code is supposed to do is to cycle between the modes when a button is pushed and output to either the LED or Buzzer or both depending on what is received from the master bluetooth module.