Scripting for dummies
Hi all
I love these BlinkM's, bought 1 about a year ago and the other 3 arrived today (no they werent the same order :P)
Anyway
I powered em up, gave em unique addresses, but I'm having some issues writing light scripts. This is something so basic that im probably just missing a step, but some input would be great.
Using the BlinkM examples, i can get each BlinkM talking with each other, i can make them all play a script, stop it on 1 BlinkM etc etc
So i thought, ill try and write my own basic light script and move up from there. But i keep hitting a wall.....
Firstly, is there a page somewhere BlinkM scripting for dummies, ive searched the net and cant find any examples on how to write BlinkM scripts.
So i open a plan Ardunio sketch, and copy the code straight from the datasheet for BlinkM into it
#include “Wire.h”
Wire.begin(); // set up I2C
Wire.beginTransmission(0x09);// join I2C bus, to BlinkM 0x09
Wire.send(‘f’); // ‘f’ == fade to color
Wire.send(0xff); // value for red channel
Wire.send(0x00); // value for blue chan.
Wire.send(0x00); // value for green chan.
Wire.endTransmission(); // leave I2C bus
and i hit upload to board, and it hits an error
error: expected constructor, destructor, or type conversion before '.' token
and highlights this line Wire.begin(); // set up I2C
i tried Begin blinkM with power to no avail.
In this test scenario it is just a single BlinkM plugged straight into the last 4 pins of arduino.
So i guess what im asking is, how do you write a light script and upload it.......
And what does that error mean, because everything i try i keep getting that exact same error
Thanks all
I love these BlinkM's, bought 1 about a year ago and the other 3 arrived today (no they werent the same order :P)
Anyway
I powered em up, gave em unique addresses, but I'm having some issues writing light scripts. This is something so basic that im probably just missing a step, but some input would be great.
Using the BlinkM examples, i can get each BlinkM talking with each other, i can make them all play a script, stop it on 1 BlinkM etc etc
So i thought, ill try and write my own basic light script and move up from there. But i keep hitting a wall.....
Firstly, is there a page somewhere BlinkM scripting for dummies, ive searched the net and cant find any examples on how to write BlinkM scripts.
So i open a plan Ardunio sketch, and copy the code straight from the datasheet for BlinkM into it
#include “Wire.h”
Wire.begin(); // set up I2C
Wire.beginTransmission(0x09);// join I2C bus, to BlinkM 0x09
Wire.send(‘f’); // ‘f’ == fade to color
Wire.send(0xff); // value for red channel
Wire.send(0x00); // value for blue chan.
Wire.send(0x00); // value for green chan.
Wire.endTransmission(); // leave I2C bus
and i hit upload to board, and it hits an error
error: expected constructor, destructor, or type conversion before '.' token
and highlights this line Wire.begin(); // set up I2C
i tried Begin blinkM with power to no avail.
In this test scenario it is just a single BlinkM plugged straight into the last 4 pins of arduino.
So i guess what im asking is, how do you write a light script and upload it.......
And what does that error mean, because everything i try i keep getting that exact same error
Thanks 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,
The code snippets in the BlinkM datasheet are just portions of a more complete Arduino sketch. All Arduino sketches must have a "setup()" and "loop()" code blocks, which you'll notice the code snippets lack.
To then the example you list into a full Arduino sketch, it would look something like this:
#include "Wire.h"
void setup() {
Wire.begin(); // set up I2C
Wire.beginTransmission(0x09);// join I2C bus, to BlinkM 0x09
Wire.send('f'); // ‘f’ == fade to color
Wire.send(0xff); // value for red channel
Wire.send(0x00); // value for blue chan.
Wire.send(0x00); // value for green chan.
Wire.endTransmission(); // leave I2C bus
}
void loop() {
}
Notice that the "#include" is outside the "setup()" block. Of course that sketch probably won't do what you want because it doesn't first stop the playback of the startup script a BlinkM normally plays when it's powered on. So a sketch that does that would look like:
#include "Wire.h"
void setup() {
Wire.begin(); // set up I2C
Wire.beginTransmission(0x09);// join I2C bus, to BlinkM 0x09
Wire.send('o'); // 'o' == stop script
Wire.endTransmission(); // leave I2C bus
Wire.beginTransmission(0x09);// join I2C bus, to BlinkM 0x09
Wire.send('f'); // ‘f’ == fade to color
Wire.send(0xff); // value for red channel
Wire.send(0x00); // value for blue chan.
Wire.send(0x00); // value for green chan.
Wire.endTransmission(); // leave I2C bus
}
void loop() {
}
You can see this is starting to get a little ungainly with just using the Wire library. That's why there's the "BlinkM_funcs.h" library you place in your sketch directory. The equivalent sketch using BlinkM_funcs.h would look like:
#include "Wire.h"
#include "BlinkM_funcs.h"
const int blinkm_addr = 0x09;
void setup() {
BlinkM_begin();
BlinkM_stopScript( blinkm_addr );
BlinkM_fadeToRGB( blinkm_addr, 0xff,0x00,0x00 );
}
void loop() {
}
Now if you have your BlinkM plugged in directly to the Arduino (instead of into a breadboard), you will have to change "BlinkM_begin()" to "BlinkM_beginWithPower()" so that the Arduino knows to turn two of its pins into a power source for BlinkM. That sketch would look like:
#include "Wire.h"
#include "BlinkM_funcs.h"
const int blinkm_addr = 0x09;
void setup() {
BlinkM_beginWithPower();
BlinkM_stopScript( blinkm_addr );
BlinkM_fadeToRGB( blinkm_addr, 0xff,0x00,0x00 );
}
void loop() {
}
For another short example, check out the BlinkMColorFader Arduino sketch in the BlinkM Examples bundle.
Loading Profile...



EMPLOYEE