Rotarty switch to change scripts
Hey again all!
So i got the whol scripting thing going thanks to your help.
All BlinkM's are powered from an external 5v adapter
But for my purposes what if like to do is store say 13 scripts in 1 sketch and upload it to ardunio. Then connect all 13 digital points to a rotary dial , and from that to a single push button switch.
So you rotate the dial to the script you want thats already on Ardunio, then hit the push button and it sends it down the i2c chain to all 8 BlinkM's
Has anyone done this before!?
I've tried using the base arduino code from here http://arduino.cc/en/Tutorial/Button and modifying the code, but it didnt work to well.... it just seemed to make it go red.
Here is the best part of my code
void setup()
{
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
BlinkM_beginWithPower();
BlinkM_stopScript(all_call); // turn off startup script
BlinkM_setRGB( all_call, 0x00,0x00,0x00);
}
void loop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
BlinkM_setRGB( all_call, 0x00,0xff,0x00);
delay(500);
BlinkM_setRGB( all_call, 0x00,0x00,0xff);
delay(500);
} else {
BlinkM_setRGB( all_call, 0xff,0x00,0x00);
}
}
Thanks in advance all!
So i got the whol scripting thing going thanks to your help.
All BlinkM's are powered from an external 5v adapter
But for my purposes what if like to do is store say 13 scripts in 1 sketch and upload it to ardunio. Then connect all 13 digital points to a rotary dial , and from that to a single push button switch.
So you rotate the dial to the script you want thats already on Ardunio, then hit the push button and it sends it down the i2c chain to all 8 BlinkM's
Has anyone done this before!?
I've tried using the base arduino code from here http://arduino.cc/en/Tutorial/Button and modifying the code, but it didnt work to well.... it just seemed to make it go red.
Here is the best part of my code
void setup()
{
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
BlinkM_beginWithPower();
BlinkM_stopScript(all_call); // turn off startup script
BlinkM_setRGB( all_call, 0x00,0x00,0x00);
}
void loop()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
BlinkM_setRGB( all_call, 0x00,0xff,0x00);
delay(500);
BlinkM_setRGB( all_call, 0x00,0x00,0xff);
delay(500);
} else {
BlinkM_setRGB( all_call, 0xff,0x00,0x00);
}
}
Thanks in advance all!
1
person has this question
I have this question, too!
Tell me when someone answers.
The more people who ask this question, the more it gets noticed.
The more people who ask this question, the more it gets noticed.
Create a customer community for your own organization
Plans starting at $19/month
-
Inappropriate?Hi Alex,
Rotary switches can be a bit tricky. And they eat up a lot of inputs. Below is a diagram of a hypothetical 5-position rotary switch hooked up to an Arduino. Connect the rotary's common connection to ground, and then hook each position connection to an Arduino input. You'll need to then either wire a resistor from each position connection to +5V or turn on the internal pull-up resistors of Arduino in your sketch.

With the above circuit, a sketch to test it out would look like the below. In setup() I turn each pin into an input and turn on the internal pull-up resistor (so you don't need the external resistors shown in the diagram). There's also a function called getRotaryValue()that you can use to get back a value that indicates the position of the rotary switch. Then you can do if() statements off that and do whatever you want. In this case, I have it printing to the serial port, but you can add the appropriate BlinkM commands you want.
// RotarySwitch.pde -- test out a rotary switch (not a rotary encoder)
// Tod E. Kurt, http://todbot.com/blog/
const int firstRotaryPin = 3;
const int lastRotaryPin = 6;
void setup() {
for( int i=firstRotaryPin; i<= lastRotaryPin; i++) {
pinMode( i, INPUT);
digitalWrite( i, HIGH); // turn on internal pullup resistor
}
Serial.begin(9600); // let's talk to the world
Serial.println("RotarySwitch ready!");
}
// returns the position of the rotary switch, 1-5
// or returns 0 if no rotary switch is hooked up
int getRotaryValue() {
for( int i=firstRotaryPin; i<= lastRotaryPin; i++) {
int val = digitalRead( i ); // look at a rotary switch input
if( val == LOW ) { // it's selected
return (i - firstRotaryPin + 1); // return a value that ranges 1 - 5
}
}
return 0; // error case
}
void loop() {
int rotaryPos = getRotaryValue();
if( rotaryPos == 1 ) {
Serial.println("Rotary Position 1");
}
else if( rotaryPos == 2 ) {
Serial.println("Rotary Position 2");
}
else if( rotaryPos == 3 ) {
Serial.println("Rotary Position 3");
}
else if( rotaryPos == 4 ) {
Serial.println("Rotary Position 4");
}
else if( rotaryPos == 5 ) {
Serial.println("Rotary Position 5");
}
else {
Serial.println("uh oh, somethings wrong");
}
delay( 100 ); // slow down the loop() so we don't spam the serial port
}
-
Inappropriate?Thanks Todbot!
So it is possible, I'll have to take a trip to Jaycar get some supplies and have a play with it! Thanks heaps
I’m happy
-
Inappropriate?No problem. Let us know how it turns out!
Loading Profile...



EMPLOYEE