|
|
|
|
|||
|
Australia, QLD
Joined Aug 2012
18 Posts
|
LeoStick Arduino + RC transmitter = goodness
Hey guys,
New to all this! I just got my LeoStick Arduino setup to read a spare channel on my receiver. It performs 8 different actions depending on the position of the transmitter knob. Currently those 8 different actions are just changing colours on the built in RGB LED, but I soon hope to wire that out to a breadboard and start controlling some relays to switch on/off bigger lights/gizmos. Here's a quick video showing the LED change color depending on the position on the transmitter.
I'm still rather newb with electronics, so I'm trying to learn how to convert the 6V coming from the BEC down to 5V so it can power this LeoStick onboard the helicopter. After I tackle that I'll be learning how to correctly wire up a relay so I can turn on/off a 12v light source from the arduino. All pretty basic stuff - but new and exciting for me! Code: Code:
#define CHANNEL 6 // which input pin on arduino to read from
#define CHANNELMIN 16900 // value of pulseIn() when tx is min
#define CHANNELMAX 17500 // value of pulseIn() when tx is max
#define MODECOUNT 6 // split input into this many different actions, plus a min/max (8 total)
#define LEDPINR 13 // RED LED
#define LEDPING 9 // GREEN LED
#define LEDPINB 10 // BLUE LED
int modewidth = (CHANNELMAX - CHANNELMIN) / MODECOUNT; // width of each action
int currentmode = 0;
void setup() {
Serial.begin(9600);
pinMode(CHANNEL, INPUT);
digitalWrite(CHANNEL, HIGH);
pinMode(LEDPINR, OUTPUT);
pinMode(LEDPING, OUTPUT);
pinMode(LEDPINB, OUTPUT);
Serial.println("Starting");
}
void loop() {
int i = pulseIn(CHANNEL, LOW);
if(i<=CHANNELMIN){
// off
//Serial.println("Min");
currentmode = 0;
}else if(i>=CHANNELMAX){
// all way on.
//Serial.println("Max");
currentmode = MODECOUNT+1;
}else{
// one of the "modes" in between.
currentmode = ((i - CHANNELMIN) / modewidth)+1;
}
Serial.println(currentmode);
switch(currentmode){
case 0:
digitalWrite(LEDPINR, LOW); //
digitalWrite(LEDPING, LOW); //
digitalWrite(LEDPINB, LOW); //
break;
case 1:
digitalWrite(LEDPINR, HIGH); //
digitalWrite(LEDPING, LOW); //
digitalWrite(LEDPINB, LOW); //
break;
case 2:
digitalWrite(LEDPINR, LOW); //
digitalWrite(LEDPING, HIGH); //
digitalWrite(LEDPINB, LOW); //
break;
case 3:
digitalWrite(LEDPINR, LOW); //
digitalWrite(LEDPING, LOW); //
digitalWrite(LEDPINB, HIGH); //
break;
case 4:
digitalWrite(LEDPINR, HIGH); //
digitalWrite(LEDPING, HIGH); //
digitalWrite(LEDPINB, LOW); //
break;
case 5:
digitalWrite(LEDPINR, HIGH); //
digitalWrite(LEDPING, LOW); //
digitalWrite(LEDPINB, HIGH); //
break;
case 6:
digitalWrite(LEDPINR, LOW); //
digitalWrite(LEDPING, HIGH); //
digitalWrite(LEDPINB, HIGH); //
break;
case 7:
digitalWrite(LEDPINR, HIGH); //
digitalWrite(LEDPING, HIGH); //
digitalWrite(LEDPINB, HIGH); //
break;
}
}
Dave |
||
|
|
|
| Thread Tools | |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Discussion Tiny Arduino perfect for RC | TinyCircuits | Product Announcements | 1 | Sep 26, 2012 03:07 PM |
| Discussion RC Segway with arduino wm+ nunchuk and multiwii code | Widelec | Multirotor Talk | 0 | Mar 07, 2012 07:43 AM |
| Discussion Spektrum / Arduino Joystick Transmitter | sonicj | DIY Electronics | 19 | Aug 16, 2010 02:13 PM |
| Question What RC Transmitter Has Good Range? | RCOnboard | Video Piloting (FPV/RPV) | 22 | Sep 18, 2009 12:56 PM |