0

What I Am Working With: I am working on a project involving an Arduino, some RGB led strip, and my PC.

My Project: The PC sends UART (serial) data to the Arduino over Bluetooth (through a HC-06 Bluetooth module connected to the Arduino) to change the color of the LED strip. The user could also change "lighting modes" to instruct the Arduino to make the LED blink, fade, etc.

My Problem: Having no RTOS nor interruptions on data reception, it would be impossible for me to make the LED fade and, also, to receive Bluetooth data to change the lighting mode.

I would appreciate whatever input the community has regarding this problem.

Thanks in advance, Stanislas.

  • 3
    Welcome. Possibly adding the code you have so far, a schematic and possibly what else you have done to attempt the project. – RSM Jun 14 '16 at 6:24
  • I'm not at home at the moment, but I'll post that as soon as I get home. – Nasta Jun 14 '16 at 6:41
  • Received serial data is being buffered (in the background). So you only need to occasionally call Serial.available to see if there's any new data. – Gerben Jun 14 '16 at 13:35
  • There are numerous tutorials available online for controlling LEDs from the Arduino over a Bluetooth connection. You might find some of them helpful: Circuit Magic's tutorial, SoldererTV's tutorial. To change the behavior of the LED, just manipulate the serial data you communicate over the HC-06 in much the same way described in these tutorials – Vladislav Martin Jun 14 '16 at 14:23
  • Also, it would be helpful to know what model of Arduino you are using when it comes to specifying the appropriate pins to use. – Vladislav Martin Jun 14 '16 at 14:24
0

Yes, it can be done. You don't need a realtime OS for something as simple as that. Basically in your loop function you would check the serial port and parse the input (if available) to see if the PC instructed the arduino to change its mode. Then you would call a function - say nextstep() - which would perform whatever the next step is, depending on your current mode. True, when you get serial input your loop() will take longer to execute, which will alter the 'rhythm' of your fades etc. If this is important, you should replace the call to delay() with a loop checking millis() against a value stored at the start of loop().

int currentmode ;
int previousmode ;

void loop()
{
   previousmode = currentmode ;
   currentmode = getnewmode(currentmode) ;
   if (currentmode != previousmode)
      initmode(currentmode) ;  // turn new mode on e.g. change LED color
   nextstep(currentmode) ;     // if current mode is dynamic, make change
   delay(DELAY_INTERVAL) ;
}

int getnewmode(oldmode)
{
   if (!serialpending()) // no serial input
      return oldmode ;
   return parseinput() ;       
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.