-1

when i use SoftPWMBegin() function in setup there is some delay while receiving data over bluetooth. And if i pressed o and 1 fastly (see in below given code), some time it receives data and sometime not receives. when i not using SoftPWMBegin() it receives data fastly . I think SoftPWMBegin() function creating some problem. I want use SoftPWM.h library for controlling RGB led brightness. So please give me any solution for that...

#include <"SoftwareSerial.h">
#include <"SoftPWM.h">

SoftwareSerial Genotronex(0, 1);

int redPin = A5;

int greenPin = 3;

int bluePin = A0;

int BluetoothData; 


void setup()

{

 Genotronex.begin(57600);

  SoftPWMBegin();

  }

void loop()
{

if (Genotronex.available())

   {

      BluetoothData=Genotronex.read();


   if(BluetoothData=='0')

   {   

  SoftPWMSet(redPin, 0);

   }

   else if(BluetoothData=='1')
{

    SoftPWMSet(redPin, 20);

   }

}

}
  • 3
    I don't understand why are you using SoftwareSerial on pins where hardware one is available and why are you using SoftPWM when there are six harware PWM pins available. There is also a slight difference between Arduino Uno and Mega. So which one is really used? – KIIV Sep 15 '16 at 11:53
0

Maybe you need to change the class that contains the SoftPWMBegin() or Genotronex.read() methods. I don't know this library, can you give the link for donwload it and to try it...?

0

Software PWM is quite complex and uses interrupts to emulate PWM using a timer. SoftwareSerial also uses interrupts. You can't have two things happening at once, so one wilk take precedence over the other. In this case the timer interrupt is taking precedence over the Pin Change interrupt, so the reception is delayed, which breaks SoftwareSerial since it relies on a prompt response to the interrupt to work.

You basically have to avoid the use of both software emulations together. Either switch to using the hardware UART, or hardware PWM or, even better, ditch both and go for 100% hardware driven.

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.