Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not work!





Switching between m...
 
Share:
Notifications

Switching between modes in a program using bluetooth  

  RSS

led bloke
(@led-bloke)
New Member
Joined: 1 month ago
Posts: 2
February 16, 2020 7:58 AM  

Hi everyone, this is my first post, i like playing with led's and i am slowly learning about Arduino's but i find it very hard with the programming so i am asking for a little help please.

I have made some garden lights and i want to be able to change between effects with my android phone via Bluetooth, i have found about 5 programs i would like to use as different effects, i can get them to run individually and continuously but i want to integrate them with Bluetooth and be able to select whatever light effect i want.

I have built an android app with app inventor (with the help of "Electronoobs" ) on YouTube and i can turn on individual leds with the app but i have tried in vain to get it to work with my program, i have looked at the program on here where all of the light displays are linked together, https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/.... i think that is the right link and using a button to switch between effects.

At last i thought, i can use a relay to replace the button and switch it with Bluetooth, simple i thought....... hmmmmmmmmmm not so easy, i have tried to comment out the effects i didn't want with // in the code but i keep getting it wrong, also the code is so long it takes seconds for the relay to switch sometimes.

I know you can put interrupts in but i have no idea how to and ware to put them, the code from the Bluetooth is...  

int rainbow=7;

int Meteor=8;

int colour t=9;

int white t=10;

int snow=11;

int rainbow_state=0;

int meteor_state =0;

int colour t_state = 0;

int white t_state = 0;

int snow_state = 0;

void setup(){

  

  Serial.begin(9600);

  pinMode(rainbow,OUTPUT);

  pinMode(meteor,OUTPUT);

  pinMode(couour t,OUTPUT);

  pinMode(white t,OUTPUT);

  pinMode(snow,OUTPUT);

}

void loop(){

 

 if(Serial.available()>0)

 { 

    Received = Serial.read();

    

 }

////////////////rainbow////////////////////

if (rainbow_state == 0 && Received == '1')

  {

    digitalWrite(rainbow,HIGH);

    rainbow_state=1;

    Received=0;  

  }

if (rainbow_state ==1 && Received == '1')

  {

    digitalWrite(rainbow,LOW);

    rainbow_state=0;

    Received=0;

  }

///////////////////////////////////////////

////////////////meteor/////////////////////

if (meteor_state == 0 && Received == 'a')

  {

    digitalWrite(meteor,HIGH);

    meteor_state=1;

    Received=0;  

  }

if (meteor_state ==1 && Received == 'a')

  {

    digitalWrite(,meteorLOW);

    meteor_state=0;

    Received=0;

  }

///////////////////////////////////////////

////////////////colour t/////////////////////

if (colour t_state == 0 && Received == '2')

  {

    digitalWrite(colour t,HIGH);

    colour t_state=1;

    Received=0;  

  }

if (colour t_state ==1 && Received == '2')

  {

    digitalWrite(colour t,LOW);

    colour t_state=0;

    Received=0;

  }

///////////////////////////////////////////

////////////////white t/////////////////////

if (white t_state == 0 && Received == '2')

  {

    digitalWrite(white t,HIGH);

    white t_state=1;

    Received=0;  

  }

if (white t_state ==1 && Received == '2')

  {

    digitalWrite(white t,LOW);

    white t_state=0;

    Received=0;

  }

///////////////////////////////////////////

  ////////////////snow/////////////////////

if (snow_state == 0 && Received == '2')

  {

    digitalWrite(snow,HIGH);

    snow_state=1;

    Received=0;  

  }

if (snow_state ==1 && Received == '2')

  {

    digitalWrite(snowLOW);

    snow_state=0;

    Received=0;

  }

///////////////////////////////////////////

 

}

I have added some buttons and renamed them but the code works fine with leds and my phone, i am using the "fast led framework" and adding my code in the reliant areas but if someone would be so kind as to show me the code to switch between displays with Bluetooth please i would be so great full.

Regards Martin (led bloke) 


ReplyQuote
Hans
 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 821
February 17, 2020 9:53 PM  

Hi LED Bloke 

Apologies for the late response ...

The idea to use a relay isn't a bad one. But I'd imagine a second Arduino would control the relay then.
I have not yet played with Bluetooth so I cannot give much advise on that topic.
Well, except that BT has a limited rang. Depending on the BT implementation version

  • Class 1 up to 100 meters (or 300 feet) - As far as I know, not very common.
  • Class 2 up to 10 meters (or 30 feet) - the most commonly used BT, often for headsets.
  • Class 3 less than than 10 meters (or 30 feet) - commonly used for keyboards and mice.
On that note: I've seen others play with BT for the LED effect, you may want to checkout their code, for example this post https://www.tweaking4all.com/forums/topic/arduino-all-effects-with-ir-support/ .
I think the main challenge will be the "interrupt" of running code (for example an effect that is currently running). A BT module will (probably) not be able to trigger an interrupt, so we'd need some kind of multitasking/task switching to "read" what the BT is receiving.
I did order a BT module the other day, and would like to tinker with this as well, so hopefully I'll be able to post working code in the next few weeks.


ReplyQuote
led bloke
(@led-bloke)
New Member
Joined: 1 month ago
Posts: 2
February 23, 2020 12:45 AM  

Thank you, it never even crossed my mind to use a second arduino with the relay connected via BT , i am on my way to my shed now to try it........... i will keep you posted.

Thank you sooooo much.

Have a good day

Regards Martin. (led bloke)


ReplyQuote
Hans
 Hans
(@hans)
Prominent Member Admin
Joined: 7 years ago
Posts: 821
February 23, 2020 1:03 AM  

I usually wouldn't think about that either - but since they are cheap and you'd solve the interrupt issue with that, this may work! 


ReplyQuote
Share: