Swapping normal LEDs in code and use NeoPixel instead

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
nico_m
 
Posts: 7
Joined: Tue Dec 31, 2013 4:44 pm

Swapping normal LEDs in code and use NeoPixel instead

Post by nico_m »

Hello,
Im gradually learning how to use arduino and have gone through a few tutorials, however I am having problems getting the Neopixel 16 LED ring to work.
I want to make this arduino lie detector or similar: http://www.erobotkits.com/arduino-proje ... -detector/
this defines the LEDs as pins, which makes sense but as the whole Neopixel is only attached to one pin, I can not get this to work. I have tried including # the library at the top of the code but still no luck

My question: How do I replace the

Code: Select all

int red_Pin = 9;
int green_Pin = 10;
int blue_Pin = 11;
int buzzer_Pin = 7;
with my Neopixel ring?

The rest of the code is below

Code: Select all

int red_Pin = 9;
int green_Pin = 10;
int blue_Pin = 11;
int buzzer_Pin = 7;
int pot_Pin = 1;
int sensor_Pin = 0;
long red = 0xFF0000;
long green = 0x00FF00;
long blue = 0×000080;
int band = 10;

void setup()
{
pinMode(pot_Pin, INPUT);
pinMode(sensor_Pin, INPUT);
pinMode(red_Pin, OUTPUT);
pinMode(green_Pin, OUTPUT);
pinMode(blue_Pin, OUTPUT);
pinMode(buzzer_Pin, OUTPUT);
}

void loop()
{
int gsr = analogRead(sensor_Pin);
int pot = analogRead(pot_Pin);
if (gsr > pot + band)
{
setColor(red);
beep();
}
else if (gsr < pot – band)
{
setColor(blue);
}
else
{
setColor(green);
}
}
void setColor(long rgb)
{
int red = rgb >> 16;
int green = (rgb >> 8) & 0xFF;
int blue = rgb & 0xFF;
analogWrite(red_Pin, 255 – red);
analogWrite(green_Pin, 255 – green);
analogWrite(blue_Pin, 255 – blue);
}
void beep()
{
// 5 Khz for 0.2 second
for (int i = 0; i < 1000; i++)
{
digitalWrite(buzzer_Pin, HIGH);
delayMicroseconds(100);
digitalWrite(buzzer_Pin, LOW);
delayMicroseconds(100);
}
}

Thanks

User avatar
Franklin97355
 
Posts: 23911
Joined: Mon Apr 21, 2008 2:33 pm

Re: Swapping normal LEDs in code and use NeoPixel instead

Post by Franklin97355 »

Take a look at the sample code and you will find how the pixels are addressed then rather than setting pins you set color and pixel number.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”