Home Project Help

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!

Moderator: phalanx

Post Reply
RobertH
Posts: 3
Joined: Thu Jun 07, 2018 1:16 pm

Home Project Help

Post by RobertH » Thu Jun 07, 2018 1:26 pm

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

Valen
Support Volunteer
Posts: 1698
Joined: Wed Dec 22, 2010 2:05 am

Re: Home Project Help

Post by Valen » Fri Jun 08, 2018 7:28 am

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.

RobertH
Posts: 3
Joined: Thu Jun 07, 2018 1:16 pm

Re: Home Project Help

Post by RobertH » Fri Jun 08, 2018 8:13 am

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.

Valen
Support Volunteer
Posts: 1698
Joined: Wed Dec 22, 2010 2:05 am

Re: Home Project Help

Post by Valen » Sat Jun 09, 2018 4:06 pm

Come up with those errors and code then.

RobertH
Posts: 3
Joined: Thu Jun 07, 2018 1:16 pm

Re: Home Project Help

Post by RobertH » Sun Jun 10, 2018 1:05 pm

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

Post Reply