Go Down

Topic: I'd like to add control of an additional light to my sketch... (Read 1 time) previous topic - next topic

Arrch


The if statements and the switch cases work individually but not as one whole program


Every time you call the read() method, the data is pulled out of the buffer. So when you call this

Code: [Select]
switch (BTSerial.read())

uncondintionally, you're never going to build up the buffer enough for available() to be greater than 3.

AllenI

Thanks for the tip, didnt realize that. I replaced Serial.read() with Serial.peek() and I have all 3 lights working now. XD Kinda. I can turn on the white led, but I cant turn it off. Some progress though. better than nothing. Any suggestions?

AllenI

Well I added Serial.read(); after digitalWrite() High or Low and it seems to have fixed it. Yeah! Feels good when things actually work. Now I just have to fix this buggy RGB led. This line is the problem:
Code: [Select]
      if (byte(BTSerial.read() == 'A'));{
       
      redvalue2=BTSerial.read();
      greenvalue2=BTSerial.read();
      bluevalue2=BTSerial.read();
    }


it works kinda but its extremely buggy. The purpose for the 'A' is to distinguish between RGB led #1 and RGB led #2. Im supposed to be able to hit the button on my app and whatever color is on RGB led #1 will then transfer to RGB led #2. But it needs cleaning up. This may be an all nighter

HazardsMind

By any chance could it be this?
Quote
if (byte(BTSerial.read() == 'A'));{
My GitHub:
https://github.com/AndrewMascolo?tab=repositories

Go Up