Go Down

Topic: LED control via Android smartphone (Read 3014 times) previous topic - next topic

kas

This BlinkM LED is controlled via an Android smartphone, using a virtual joystick

http://www.youtube.com/watch?v=Mapb0MIz6GQ

More info re Joystick Bluetooth Commander application in the Networking section

Enjoy

oric_dan

Cool, is there an .ino associated with this to look at?

kas

#2
Jul 19, 2013, 09:04 am Last Edit: Jul 19, 2013, 09:06 am by kas Reason: 1
Quote
Cool, is there an .ino associated with this to look at?


Sure

Code: [Select]
// AndroBlinkM V1.2
// Arduino test sketch for Joystick BT Commander
// Drive a BlinkM LED

// * BlinkM connections to Arduino
// * GND     Analog 2
// * +5V     Analog 3
// * SDA     Analog 4
// * SCK     Analog 5

#include "Wire.h"
#include "BlinkM_funcs.h"

#define    DEBUG          true

#define    blinkm_addr  0x00
#define    ledPin       13                // LED pin
#define    STX          0x02
#define    ETX          0x03

int i=0;
int cmd[5] = {9, 9, 9, 9, 9};

void setup()  {
 Serial.begin(57600);                   // Adjust to your specific BT Board
 pinMode(ledPin, OUTPUT);

 BlinkM_beginWithPower();  
 BlinkM_stopScript( blinkm_addr );      // turn off BlinkM startup script
 BlinkM_fadeToRGB( blinkm_addr, 0x00, 0x00, 0x00);
}

void loop() {
  if(Serial.available())  {             // Data received from smartphone
   delay(5);
   cmd[0] =  Serial.read();  
   if(cmd[0] == STX)  {  
     i=1;      
     while(Serial.available() && ((cmd[i]=Serial.read()) != ETX)) {
       if(i>3)  break;
       i++;
     }
   }
 if(i==2)    setLED(cmd[1]);
 if(i==3)    setBlinkM(cmd[1], cmd[2]);  
 }
 delay(5);
}

void setBlinkM(int hue, int bright)    {
 hue = map(hue, 10, 110, 0, 255);
 bright = map(bright, 10, 110, 0, 255);
 bright = constrain(bright, 7, 255);
 if(DEBUG)    { Serial.print(hue);  Serial.print(", ");  Serial.println(bright); }  // ** DEBUG **
 BlinkM_fadeToHSB(blinkm_addr, hue, 255, bright);    // set blinkM hue & brightness
 delay(20);
}

void setLED(int LEDstatus)  {
 switch (LEDstatus) {
   case '1':
     if(DEBUG)    Serial.println("Button: ON");    // ** DEBUG **
     digitalWrite(ledPin, HIGH);
     BlinkM_setRGB( blinkm_addr, 0xff, 0xff, 0xff);
     break;
   case '2':
     if(DEBUG)    Serial.println("Button: OFF");    // ** DEBUG **
     digitalWrite(ledPin, LOW);
     BlinkM_setRGB( blinkm_addr, 0x00, 0x00, 0x00);
     break;
 }
}



loop() code is identical as the pan/tilt project shown in the Robotic Section




More info for blinkM here

kas

#3
Aug 03, 2013, 07:58 am Last Edit: Aug 03, 2013, 08:04 am by kas Reason: 1


Joystick Bluetooth Commander Version 2.5 here

kas

Arduino sketch needs to be modified for Joystick Bluetooth Commander V3.X
(modified communication protocol)
More details here

kas

Joystick Bluetooth Commander is now Version 5.1



Code should be updated with new communication protocol
More info here and here


Go Up