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>
