Summary
LED light that operates off iPhone app. Apple does not let you may your own iPhone apps. The only way I could find to control Bluetooth with my phone was with Dabble.
You must download Dabble app on your phone.
I used:
Common anode RGB light and 100K ohm resister on each leg
Bluetooth module: HM-10
Arduino Nano
Nano I/O Breakout Expansion Board Shield
The shield is used so NANO can be removed for other projects.
Bluetooth is attached using small perf board and header pins - allows easy removal of Bluetooth.
Resisters are attached using small perf board - done to keep wires neat
LED legs are connected to NANO pins 5,6, and 9 - Red, Green, Blue - ground leg connected to ground. A 100K resister is in series with each color leg
HM-10 VCC to NANO 3.3 volt
GND to NANO ground
TXD to NANO pin 2
RXD to NANO pin 3
DABBLE uses pins 2 and 3 for TXD and RXD - it is a clever set-up - allows uploading of sketches without disconnecting HM-10 (normally Arduino uses TXD and RXD when uploading sketches)
Open Arduino IDE and include DABBLE
Add LedControlModule.h to code (see photo)
Code:
define CUSTOM_SETTINGS
define INCLUDE_GAMEPAD_MODULE
include
//Right motor
int Red=5;
int Green=9;
int Blue=6;
//int L=0;
//int H=255;
void setup()
{
// put your setup code here, to run once:
pinMode(Red,OUTPUT);
pinMode(Green,OUTPUT);
pinMode(Blue,OUTPUT);
analogWrite(Red,0);
analogWrite(Green,0);
analogWrite(Blue,0);
Serial.begin(9600);
Dabble.begin(9600, 2, 3);
}
void loop()
{
Dabble.processInput();
if (GamePad.isUpPressed())
{
//Red Light
Serial.println("Up");
analogWrite(Red,255);
analogWrite(Green,0);
analogWrite(Blue,0);
}
if (GamePad.isDownPressed())
{
//Blue Light
Serial.println("Down");
analogWrite(Red,0);
analogWrite(Green,0);
analogWrite(Blue,255);
}
if (GamePad.isLeftPressed())
{
//Green Light
Serial.println("Left");
analogWrite(Red,0);
analogWrite(Green,255);
analogWrite(Blue,0);
}
if (GamePad.isRightPressed())
{
//Purple Light
Serial.println("Right");
analogWrite(Red,255);
analogWrite(Green,0);
analogWrite(Blue,255);
}
if (GamePad.isTrianglePressed())
{
//Low Red Light
Serial.println("triangle");
analogWrite(Red,50);
analogWrite(Green,0);
analogWrite(Blue,0);
}
if (GamePad.isCrossPressed())
{
//Cyan Light
Serial.println("Cross");
analogWrite(Red,0);
analogWrite(Green,100);
analogWrite(Blue,255);
}
if (GamePad.isSquarePressed())
{
//Light Purple Light
Serial.println("Square");
analogWrite(Red,50);
analogWrite(Green,0);
analogWrite(Blue,50);
}
if (GamePad.isCirclePressed())
{
//Light Blue Light
Serial.println("Circle");
analogWrite(Red,0);
analogWrite(Green,0);
analogWrite(Blue,50);
}
if (GamePad.isSelectPressed())
{
//Light Off
Serial.println("Select");
analogWrite(Red,0);
analogWrite(Green,0);
analogWrite(Blue,0);
}
if (GamePad.isStartPressed())
{
//White Light
Serial.println("Start");
analogWrite(Red,222);
analogWrite(Green,222);
analogWrite(Blue,222);
}
}
Теги
Источник модели
