Random zeros when I change RGB values. Help!
I have an array of 20 BlinkMs connected to a PING))) sensor. The color changes as someone gets closer. I did a test and it works fine. Now want to change the number of steps and the change from white (far) to red (near). Whenever I change the RGB values I get random readings of 0 returned at regular intervals. This NEVER happens with the test set up. I am using the EXACT same code just with different RGB values. If anyone has any ideas I will be very grateful. This has me going nuts. Here is my working test code:
#include "Wire.h"
#include "BlinkM_funcs.h"
#define BLINKM_ADDR 0x09
int pin = 7;
unsigned long duration;
void setup()
{
BlinkM_begin();
BlinkM_setAddress (BLINKM_ADDR);
BlinkM_stopScript(0x09);
Serial.begin(9600);
}
void getAdistance(){
pinMode(pin, OUTPUT);
delay(1);
digitalWrite(pin, LOW);
delayMicroseconds(5);
digitalWrite(pin, HIGH);
delayMicroseconds(5);
digitalWrite(pin, LOW);
pinMode(pin, INPUT);
duration = pulseIn(pin, HIGH);
}
void loop()
{
getAdistance();
Serial.println(duration, DEC);
delay(50);
if(duration>20000){
BlinkM_setRGB(0x09,153,0,255);
delay(100);
BlinkM_fadeToRGB(0x09,0,0,255);
Serial.print("IS THERE ANYBODY OUT THERE? ");}
if ((duration<19999>10001)){
BlinkM_fadeToRGB(0x09,255,102,0);
Serial.print("HEY YOU! ");}
if((duration<10000>3001)){
BlinkM_fadeToRGB(0x09,0,255,0);
Serial.print("HELLO! ");}
if(duration<3000>
#include "Wire.h"
#include "BlinkM_funcs.h"
#define BLINKM_ADDR 0x09
int pin = 7;
unsigned long duration;
void setup()
{
BlinkM_begin();
BlinkM_setAddress (BLINKM_ADDR);
BlinkM_stopScript(0x09);
Serial.begin(9600);
}
void getAdistance(){
pinMode(pin, OUTPUT);
delay(1);
digitalWrite(pin, LOW);
delayMicroseconds(5);
digitalWrite(pin, HIGH);
delayMicroseconds(5);
digitalWrite(pin, LOW);
pinMode(pin, INPUT);
duration = pulseIn(pin, HIGH);
}
void loop()
{
getAdistance();
Serial.println(duration, DEC);
delay(50);
if(duration>20000){
BlinkM_setRGB(0x09,153,0,255);
delay(100);
BlinkM_fadeToRGB(0x09,0,0,255);
Serial.print("IS THERE ANYBODY OUT THERE? ");}
if ((duration<19999>10001)){
BlinkM_fadeToRGB(0x09,255,102,0);
Serial.print("HEY YOU! ");}
if((duration<10000>3001)){
BlinkM_fadeToRGB(0x09,0,255,0);
Serial.print("HELLO! ");}
if(duration<3000>

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?I don't know why but the end of my question is getting cut off. The code should end:
if(duration < 3000){
BlinkM_fadeToRGB(0x09,255,0,0);
Serial.print("BACK OFF! ");}
delay(500);
}
I’m confused
-
Inappropriate?Hi,
That's a really beautiful lamp.
GetSatisfaction currently screws up code formatting, so it's hard to see if the oddities in your sketch are from you or being mistranslated. Please email me your sketch at blinkm at thingm.com.
When you say "add more steps", I assume you mean adding more if-statements?
Loading Profile...



EMPLOYEE