Home Project Help

Hi All,

I could really use some help with a small project I am doing at home. Could someone please help with the code?

I have found two separate programs which I need to use but am having trouble combining them.

I have a program which operates a IR distance module and another program which lights up some Neo Pixel LED’s. The Neo Pixel program I have used to be quite long as it did lots of different light effects but I shortened it cause I only want them to fade through different colours. Both of these work on there own.

What I would like to do is when the IR module picks up an object it will light the LED’s and make them change colour as long as the module still senses something. And when the object is removed it stops. It appears to be a simple task but I am having real trouble using both of the programs together to make this happen. If anyone could help I would really appreciate it.

The IR module code I have is:


int LED = 13; // Use the onboard Uno LED

int isObstaclePin = 7; // This is our input pin

int isObstacle = HIGH; // HIGH MEANS NO OBSTACLE

void setup() {

pinMode(LED, OUTPUT);

pinMode(isObstaclePin, INPUT);

Serial.begin(9600);

}

void loop() {

isObstacle = digitalRead(isObstaclePin);

if (isObstacle == LOW)

{

Serial.println(“OBSTACLE!!, OBSTACLE!!”);

digitalWrite(LED, HIGH);

}

else

{

Serial.println(“clear”);

digitalWrite(LED, LOW);

}

delay(200);

}


And the neo pixel code for changing colours I have is:


#include <Adafruit_NeoPixel.h>

#ifdef AVR_ATtiny85 // Trinket, Gemma, etc.

#include <avr/power.h>

#endif

#define PIN 0

Adafruit_NeoPixel strip = Adafruit_NeoPixel(95, PIN, NEO_GRB + NEO_KHZ800);

void setup() {

#ifdef AVR_ATtiny85 // Trinket, Gemma, etc.

if(F_CPU == 16000000) clock_prescale_set(clock_div_1);

// Seed random number generator from an unused analog input:

randomSeed(analogRead(2));

#else

randomSeed(analogRead(A0));

#endif

strip.begin();

strip.show(); // Initialize all pixels to ‘off’

}

void loop() {

rainbow(20);

}

void rainbow(uint8_t wait) {

uint16_t i, j;

for(j=0; j<256; j++) {

for(i=0; i<strip.numPixels(); i++) {

strip.setPixelColor(i, Wheel((i+j) & 255));

}

strip.show();

delay(80);

}

}

uint32_t Wheel(byte WheelPos) {

if(WheelPos < 85) {

return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);

} else if(WheelPos < 170) {

WheelPos -= 85;

return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);

} else {

WheelPos -= 170;

return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);

}

}


Apologies if i have anything wrong.

Thanks in advance for any help.

Rob

That Rainbow routine is just a fancy way of blinking a led. And the IR code is also pretty much the Blink sketch. If you want to have the IR code stop the Rainbow code then I suggest you start looking at how the Blink-without-delay sketch is built.

Hi

Thanks for the reply. I need the rgb led to fade through colours, not blink.

Also, I don’t want the ir code to stop the led.i need it to start the led changing colour when it sees an object.

It seems really simple as I should be able to just replace the part of the ir code that turns on and off an led with a piece off code that starts changing colour of the rgb led. Yet however I add in the neopixel code it just throws up errors.

Thanks.

Come up with those errors and code then.

Wow! You should take up helping people for a living. Your great at it! :?

I can only help with solving a problem in the code if I know what the code is and what the problem is. The error code explains that. And you never showed your merged code.

In fact, I am helping people for a living in IT. And they appreciate my way of solving things. I do that by asking them for further information that narrows down to the cause. Looking into Magic orbs does not work well.