Today's 'Fun with Flowcode' project.
I wanted to tie together several ideas based on recent (and historic) forum topics. (Bluetooth, parsing commands in a datastream, converting Ascii to int and i2c)
So here we have a Bluetooth controlled mood light.
I used a BlinkM MaxM Blaster LED - which is bright (very bright) - but this would be easy to convert to another LED light (even PWM RGB for a low budget (& low light) option) (see https://thingm.com/fileadmin/thingm/dow ... asheet.pdf)
The circuit is simple - the LED controller is connected via i2c to a4/a5 on the Arduino (with 4.7k pullups) The LEDs need a separate power supply (in this case I'm using a 12v adapter)
Bluetooth (HC-05) is connected to Tx and Rx pins on the Arduino via a level shifter for the data pins (to bring things down to 3.3v) The level shifter needs 5v, and 3.3v sources and 2x GND.
I wanted a slightly more general command structure - so I'm using a 3 character command string for matching to received data (I convert the received data to upper case to allow more easier operation) - currently there are 4 commands (RED set red, BLU set blue and GRN set green (0..255 value) and PRG - set demo mode to 'n'. Note that I convert the commands to a long integer value (there isn't an easy way to initialise an array of strings in FC) It would be easy to allow 4 character commands.
So for example red255 would set RED LED to max brightness
PRG018 would set demo 18 running.
Commands can be chained (eg RED255BLU100GRN100) - though it works it doesn't make much sense to chain PRG commands.
Commands are echoed to Bluetooth - the data could also be sent via USB (using a terminal prog) - commands are not echoed (but it works ok)
The command set current is ABCnnn where ABC is the command string and nnn is a 3 (or less) digit decimal value. it would be good to have a RGBrrrgggbbb command - but I've left this out for simplicity..
Martin(1) - a graphical front end for the controller would be great (sliders for RG and B!) or a SCADA front end!
I used Serial Bluetooth (free on Play Store) on my (Android) phone.
Tips, Tricks and methods for programming, learn ways of making your programming life easier, and share your knowledge with others.
1 post • Page 1 of 1
- Valued Contributor
- Posts: 699
- Joined: Wed May 31, 2017 11:57 am
- Has thanked: 63 times
- Been thanked: 403 times
- Rating: 30%