Alan,
Any chance you can help. I'm an Arduino newbie. But basically I followed another tutorial to hack some IKEA DIODER Lights, you remove the controller, wire to Red, Green, Blue, a common ground and common +5v. The following .ino works when uploaded via the Arduino IDE...
**********************************************************************************************
// color swirl! connect an RGB LED to the PWM pins as indicated
// in the #defines
// public domain, enjoy!
#define REDPIN 5
#define GREENPIN 6
#define BLUEPIN 3
#define FADESPEED 5 // make this higher to slow down
void setup() {
pinMode(REDPIN, OUTPUT);
pinMode(GREENPIN, OUTPUT);
pinMode(BLUEPIN, OUTPUT);
}
void loop() {
int r, g, b;
// fade from blue to violet
for (r = 0; r < 256; r++) {
analogWrite(REDPIN, r);
delay(FADESPEED);
}
// fade from violet to red
for (b = 255; b > 0; b--) {
analogWrite(BLUEPIN, b);
delay(FADESPEED);
}
// fade from red to yellow
for (g = 0; g < 256; g++) {
analogWrite(GREENPIN, g);
delay(FADESPEED);
}
// fade from yellow to green
for (r = 255; r > 0; r--) {
analogWrite(REDPIN, r);
delay(FADESPEED);
}
// fade from green to teal
for (b = 0; b < 256; b++) {
analogWrite(BLUEPIN, b);
delay(FADESPEED);
}
// fade from teal to blue
for (g = 255; g > 0; g--) {
analogWrite(GREENPIN, g);
delay(FADESPEED);
}
}
**********************************************************************
I was hoping to have similar control over the LEDs using the PyMata, however I'm having trouble finding an example that uses PWM and allows analog writes.
I thought something like this would work but it seems to output nothing. Do you have any suggestions?
***************************************************************************************
import time
from PyMata.pymata import PyMata
# Give the pins names:
REDPIN = 5
GREENPIN = 6
BLUEPIN = 3
FADESPEED = 5
# Create an instance of PyMata.
SERIAL_PORT = "/dev/ttyS0"
firmata = PyMata( SERIAL_PORT, max_wait_time=5 )
# initialize the digital pin as an output.
#firmata.set_pin_mode( LED, firmata.OUTPUT, firmata.DIGITAL )
firmata.set_pin_mode( REDPIN, firmata.OUTPUT, firmata.PWM)
firmata.set_pin_mode( GREENPIN, firmata.OUTPUT, firmata.PWM)
firmata.set_pin_mode( BLUEPIN, firmata.OUTPUT, firmata.PWM)
try:
# run in a loop over and over again forever:
while True:
#for r in range (0,256,1):
firmata.analog_write( REDPIN, 255 )
firmata.analog_write( GREENPIN, 0 )
firmata.analog_write( BLUEPIN, 255 )
time.sleep(1.0) # wait for a second
except KeyboardInterrupt:
# Catch exception raised by using Ctrl+C to quit
pass
# close the interface down cleanly
firmata.close()