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