Hello, I am using a esp8622-12e nodemcu to build a base station for my sensor network. When activated the station displays message on lcd, starts buzzing alarm and flashes an led. Then I had the idea to replace my series of led's (specific color led for each event) with a RGB led. That worked great but introduced a problem with the buzzer, namely the buzzer doesnt work when using the rgb led.
I think the problem is that the rgb led uses analogWrite() and the buzzer uses tone() and the esp8266 will not support more than 1 analog pin at a time. I think...
I've experimented with using noTone() in different ways to free up the pin but to no avail.
If there are any suggestions on how this could work I would be greatly appreciative. If I cannot come to a solution I may integrate an mp3-tf-16p which -I believe- would eliminate any analog conflicts with the rgb led but would be overkill when all I want is annoying buzzing. If that is in fact the problem.
void HallwayTrip(){ //this function called when hall sensor sends a signal
while(HallwayMotionState == 1){ //while alarm is active
if (digitalRead(buttonApin) == LOW) { //clear alarm upon pushing button
HallwayMotionState = 0;
analogWrite(RLedPin, 0);
analogWrite(BLedPin, 0);
analogWrite(GLedPin, 0);
lcdDisplay(" ",0,0);
lcdDisplay(" ",0,1);
lcd.setBacklight(0); //off
}
if (millis() - lastHallwayMillis > 1000) { //buzzes and flashes during alarm
lastHallwayMillis = millis();
buzzBuzzer(650,750); //buzz the buzzer
flashLed(1); //flash the led
}
client.loop(); //keeps station connection alive during alarm
delay(10);
}
}
void buzzBuzzer(int buzzFreq, int buzzLength){ //buzzes differently for each alarm event
tone(BuzzPin, buzzFreq, buzzLength);
}
void flashLed(int LedID){ //experimental implementation of the rgb led, LedID is used to differentiate alarm events with patterns and colors
switch(LedID){
case 1: //Hallway motion LED
if(flipSwitch == 0){analogWrite(RLedPin, 0);analogWrite(BLedPin, 255);analogWrite(GLedPin, 0); flipSwitch = 1; break;} //blue
if(flipSwitch == 1){analogWrite(RLedPin, 0);analogWrite(BLedPin, 0);analogWrite(GLedPin, 0); flipSwitch = 2; break;} //off
if(flipSwitch == 2){analogWrite(RLedPin, 0);analogWrite(BLedPin, 255);analogWrite(GLedPin, 128); flipSwitch = 3; break;} //teal
if(flipSwitch == 3){analogWrite(RLedPin, 0);analogWrite(BLedPin, 0);analogWrite(GLedPin, 0); flipSwitch = 0; break;} //off
}
}
I've grown frustrated and know it is either super simple and I just don't get it or I am on the wrong track. Any advice or insight is most welcome.