Why is pinMode (tiltswitch, INPUT) producing an error? [closed] - arduino

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 days ago.
Improve this question
Ok, so I am trying to control the Pixel lights and make it so the first pixel changes color if a tilt switch tilts. I don't know why it will not let me pinMode.. It spits out the error Compilation error: expected constructor, destructor, or type conversion before '(' token
I notated below in the sketch where that error occurs. I am just starting out with Arduino, so I really don't have a full grasp and I am using existing sketches and learning as I go by adding code that I have figured out to do the things I want.
Below is my modified code to give the first 8 pixels specific colors, and change the color of Pixel 1 when the tilt switch tilts:
#include <Adafruit_NeoPixel.h> // include the Neopixel Library in this Sketch
#define PIN 6 // This is the Arduino Pin controlling the LEDstrip.
#define NUMPIXELS 8 // Here, you are informing how many LEDs you have on your strip.
// You can also control only a part of the existing LEDs, if you wish.
// This strip has 60 LEDs, so I am informing this number.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800); // Here, you are specifying your strip
// The strip I am using has 50 LEDs. I want to control it in 6 groups of 1 LEDs, to make my life easier.
* So, let's define the following arrays:
*/
int PXL1[] = {0}; // array controlling the first LED. Please notice the "LED 0" is the first one, not "LED 1"
int PXL2[] = {1};
int PXL3[] = {2};
int PXL4[] = {3};
int PXL5[] = {4};
int PXL6[] = {5};
int PXL7[] = {6};
int tiltswitch = 3;
pinMode (tiltswitch, INPUT); //THIS LINE IS PRODUCING THIS ERROR: Compilation error: expected constructor, destructor, or type conversion before '(' token
void setup() {
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
for(int i=0;i<1;i++){ // Since each array has 10 LEDs, we are going to turn them sequentially on using this index.
/*
* Notice that the lines below are just setting up the color of each pixel. This is not yet the command to turn them on. The
* pixels.setPixelColor command is a very easy way to define the color of each pixel. The syntax is:
* pixels.setPixelColor(x, pixels.Color(R,G,B)), where:
* x = the pixel you want to define a color for. In this example, we are using the arrays we created for the 6 control groups, hence the PXL1[i] input.
* R,G,B = the values of red, green, and blue on a RGB scale.
*/
// array number 1 is magenta
pixels.setPixelColor(PXL2[i], pixels.Color(255,255,0)); // array number 2 is yellow
pixels.setPixelColor(PXL3[i], pixels.Color(255,255,255)); // array number 3 is white
pixels.setPixelColor(PXL4[i], pixels.Color(0,255,0)); // array number 4 is green
pixels.setPixelColor(PXL5[i], pixels.Color(0,0,255)); // array number 5 is blue
pixels.setPixelColor(PXL6[i], pixels.Color(255,0,0)); // array number 6 is red
pixels.setPixelColor(PXL7[i], pixels.Color(10,100,200)); // array number 6 is red
pixels.show(); // Okay, we have informed which colors we want. Now, it is time to flip the switch and let the magic happen. The pixels.show() command does that
if (digitalRead(tiltswitch) == HIGH) // if the button is not pressed
pixels.setPixelColor(PXL1[i], pixels.Color(139,0,139)); // LED is purple
else // if the button is pressed
pixels.setPixelColor(PXL1[i], pixels.Color(255,255,255)); // LED is white
}
}
I was expecting the line
pinMode (tiltswitch, INPUT)
to work

As per the comment from jasonharper, it must be called inside a function. Move it to inside the setup() function.
Cutting your code back to the minimum required to reproduce, this causes the error:
int tiltswitch = 3;
pinMode(tiltswitch, INPUT);
void setup() {
}
while this works correctly, no error:
int tiltswitch = 3;
void setup() {
pinMode(tiltswitch, INPUT);
}

Related

ESP32 Interrupt jitter at 20kHz

I would like your help to solve the following problem.
I'm using an ESP32 Dev Kit V1 connected as follows:
Pin 4 (input) is connected to a 20kHz and 3.3V signal and to channel 1 of the oscilloscope; and
Pin 2 (output) is connected to channel 2 of the oscilloscope.
My goal is to use interrupts and generate a signal on pin 2 (output) that follows the variations of the signal on pin 4 (input).
The image below illustrates two behaviors. The most frequent and the other one that happens occasionally.
In the first behavior, the latency is around 3 us, but sometimes there is a variation (jitter) and the rise of the output signal takes 15 us or even more to keep up with the input.
I would like to know how to remove this occasional behavior and keep the system stable.
The code that I'm using is below. To compile and upload I am using the latest Arduino IDE version 1.8.13.
I'm using GPIO.out_w1ts and GPIO.out_w1tc because I believe it will be faster than using digitalWrite(pin, state).
Also notice that I'm not reading the state of pin 4 (input) to be faster, because of this, sometimes the output signal gets inverted, but that's not a problem at this point.
#define OUTPUT_PIN 2
#define INPUT_PIN 4
volatile bool state = false;
void IRAM_ATTR interruptFunction() {
if (state)
GPIO.out_w1ts = 0b100;
else
GPIO.out_w1tc = 0b100;
state = !state;
}
void setup() {
pinMode(INPUT_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(INPUT_PIN), interruptFunction, CHANGE);
gpio_config_t io_conf;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = 0b100;
gpio_config(&io_conf);
}
void loop() {
}
The settings used in the Arduino IDE are illustrated in the next image.
Thanks in advance for all the help!

How to program own Wifi "Mute" Stomp Box to remote control a Behringer X32 Rack?

I´m totally new to coding, this is even my first post here. Im tryng this because nobody sells what I want/need ;-).
I achived already quite a bit, but at this moment I´m getting lost with a lot of things (I read a lot about coding in general and in special with Arduino the last 8 dayas)... but let me explain first what my intention on this project is:
I want to build a "Stomp Box" to mute a Behringer X32 Rack (wireless) Channels/Mutegroups/Buses, just Mute On/Off.. nothing else.
This Box should have 4-6 "stompers" (buttons), each of this buttons should have a different Mute function.
Also the current state of the Channel/Mutegroup/Bus should be indicated by LED´s green if unmuted or red if muted.
Therfore the box needs to evaulate the current state of the designated Channel/Mutegroup/Bus, because it could change also from other remote devices.
And then switch to the opposite state when pressing/stomping on designated button.
I´d like to have code where I can easily change the action of a button, Like:
button1 = /ch/01/mix/on ,i 1
button2 = /config/mute/1 ,i 1
button3 = /dca/1/on ,i 1
so in case I need a differnt Channel/Mutegroup/Bus for another event simply edit and recode my ESP32 Node Kit
So here is my code I already have:
#include "WiFi.h"
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <SPI.h>
#include <OSCMessage.h> //https://github.com/CNMAT/OSC
#define WIFI_NETWORK "xxxxxxxxxx" //SSID of you Wifi
#define WIFI_PASSWORD "xxxxxxxxxxx" //Your Wifi Password
#define WIFI_TIMEOUT_MS 20000 // 20 second WiFi connection timeout
#define WIFI_RECOVER_TIME_MS 30000 // Wait 30 seconds after a failed connection attempt
int muteOn = 0;// 0=Mute
int muteOff = 1;// 1=Unmute
int input;
WiFiUDP Udp;
const IPAddress outIp (192, 168, 10, 129); //Mixers IP
const unsigned int outPort = 10023; //X32 Port
//variables for blinking an LED with Millis
const int led = 2; // ESP32 Pin to which onboard LED is connected
unsigned long previousMillis = 0; // will store last time LED was updated
const long interval = 300; // interval at which to blink (milliseconds)
int ledState = LOW; // ledState used to set the LED
void connectToWiFi(){
Serial.print("Zu WLAN verbinden...");
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_NETWORK, WIFI_PASSWORD);
unsigned long startAttemptTime = millis();
while(WiFi.status() != WL_CONNECTED && millis() - startAttemptTime < WIFI_TIMEOUT_MS){
Serial.println(".");
delay(100);
}
if(WiFi.status() != WL_CONNECTED){
Serial.println("Nicht Verbunden!");
//optional take action
}else{
Serial.print("WLAN Verbunden mit ");
Serial.println(WIFI_NETWORK);
Serial.println(WiFi.localIP( ));
}
}
void setup() {
Serial.begin(115200);
connectToWiFi();
Udp.begin(8888);
pinMode(led, OUTPUT);
// Port defaults to 3232
// ArduinoOTA.setPort(3232);
// Hostname defaults to esp3232-[MAC]
// ArduinoOTA.setHostname("myesp32");
// No authentication by default
// ArduinoOTA.setPassword("admin");
// Password can be set with it's md5 value as well
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
ArduinoOTA
.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("Start updating " + type);
})
.onEnd([]() {
Serial.println("\nEnd");
})
.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
})
.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
else if (error == OTA_END_ERROR) Serial.println("End Failed");
});
ArduinoOTA.begin();
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loop(){
ArduinoOTA.handle();
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
ledState = not(ledState);
// set the LED with the ledState of the variable:
digitalWrite(led, ledState);
}
input=Serial.read();
if (input=='0'){
// welcher status hat der kanal?
// wenn Kanal gemutet dann unmute und umgekehrt
Serial.println("Mute!");
delay(100);
sendMute(); //send Mute to Mixer
Serial.println("...");
}
if (input=='1'){
Serial.println("UnMute!");
delay(100);
sendUnMute();
Serial.println("...");
}
}
void sendMute() {
//the message wants an OSC address as first argument
OSCMessage msg("/ch/01/mix/on");
msg.add(muteOn);
Udp.beginPacket(outIp, outPort);
msg.send(Udp); // send the bytes to the SLIP stream
Udp.endPacket(); // mark the end of the OSC Packet
msg.empty(); // free space occupied by message
delay(20);
}
void sendUnMute() {
//the message wants an OSC address as first argument
OSCMessage msg("/ch/01/mix/on");
msg.add(muteOff);
Udp.beginPacket(outIp, outPort);
msg.send(Udp); // send the bytes to the SLIP stream
Udp.endPacket(); // mark the end of the OSC Packet
msg.empty(); // free space occupied by message
delay(20);
}
So I testet this via serial Monitor, when I input "0" and click send, the mixer mutes channel 1 and on input "1" channel 1 becomes unmuted, so far so good... (OSCMessage msg("/ch/01/mix/on"); ... section.
What bothers me here in special is, I had to hardcode the command "/ch/01/mix/on", because I am not able to declare a variable? for this string? I am already so confused that I don´t know if I even have the terms right :-(
BTW: There are a lot solutions out there how to do it with MIDI, but MIDI is not wireles and I think for my project overkill. I also did some some research on github.com/CNMAT/OSC but I don´t get it... (crying)...
I found also a post here, but this didn´t helped either... :-(
Any advice on that how I can reach my goal?--
Any help is much apprceiated... even in German (my native language... )
PS: Yes I´m a begginner and I admit it. But at least I managed how to connect and flash this thing even via OTA in the last 8 days, so please be easy on me.
Not wanting to hardcode your commands is a good instinct.
The Arduino language is C++, which is (mostly) a superset of C. C and C++ use a preprocessor which lets you define constants and test for their presence.
For instance, you could write:
#define CHAN01_MIX_ON_COMMAND "/ch/01/mix/on"
and then use CHAN01_MIX_ON_COMMAND anywhere you want to use that constant, like so:
void sendMute() {
//the message wants an OSC address as first argument
OSCMessage msg(CHAN01_MIX_ON_COMMAND);
Then if you ever need to change the string "/ch/01/mix/on" you can just change it in one location and not worry about finding every instance of it in your code.
Writing the names in #define statements is a convention people usually follow in order to make it more clear that they're constants.
You have to write the #define line before you use the constant you defined, so putting it at the start of the file (after any #include lines and before your first function) is a good practice. Or if you have several you might put them all in their own file called something like commands.h (the .h means header file)and then include that at the start of any file that needs it like so:
#include "commands.h"
This #include statement would insert the contents of the file commands.h into the file that the statement is in.
When you have several #define statements, keeping them all together in one place (whether it's at the top of the file or in their own file) is also a good practice so that you have one central place to find them and update them if you need to.
Some people will assign the string constant to a variable like so:
char *channel01_mix_on_cmd = "/ch/01/mix/on";
Here char means "a character" - like one letter or number or symbol. The * means pointer to, which lets you use an array of characters. Simple strings in C and C++ are just arrays of characters (or a pointer to the first character), with a special hidden character at the end set to numeric value 0 (not the character '0'). C++ also has a string datatype called std::string and Arduino programs have String but those are both overkill here. They all let you work with strings; String is much easier to use than char * but both have strengths and weaknesses.
Like the #define, you'd also place that outside a function near the start of the file. It defines a global variable that would be available to any function that references it.
You'd also use the variable anywhere they want the string. It's the same idea as using #define, just done slightly differently. For instance:
void sendMute() {
//the message wants an OSC address as first argument
OSCMessage msg(channel01_mix_on_cmd);
Using a variable here is an attempt to save storage by not having multiple copies of the string. It's not necessary; C/C++ compilers have for a very long time detected this and stored only one copy of the string. It might save space if your code is split into multiple files.
Saving space on CPUs like the ESP32 and ESP8266 is important because they have so little memory. #define is fine here because the compiler does it automatically for you.
You can create the command string with sprintf.
so for example:
#define CHANNELON "on"
#define CHANNELOFF "off"
int channel;
int mute;
char messageString[100];
// some code that calculates the channel number and the mute state:
channel = 1;
mute = 1;
// then check the mute state and create the command string:
if (mute)
{
// to turn off a channel:
sprintf(messageString,"/ch/%02d/mix/%s",channel,CHANNELOFF);
}
else
{
// to turn on a channel:
sprintf(messageString,"/ch/%02d/mix/%s",channel,CHANNELON);
}
// send the command:
OSCMessage msg(messageString);
the %02d will substitute an integer with a zero in front,
if it's smaller than 10 and that is always 2 characters long.
so if channel is 1, the result would be 01

Fading Adafruit neopixels

I would like to create a motion-controlled night light for my corridor. For my project I have
Arduino Uno
PIR sensor
WS2812b RGBW light strip
5V power bank to drive the LEDs
After tinkering with my light strip, I have managed to get the LEDs to turn on and fade to a low Red color followed by a delay and finally fade back to a point where they turn off. As I understand the Neopixel library, maximum light intensity has a value of 255. However, as we're talking about night light, I estimate that a value of less than 20 is more than sufficient to illuminate my corridor. (I should note that I see many suggestions placing a resistor in front of the LED strip and a capacitor on the power supply - will this affect intensity?) As a consequence, the light does not fade/turn off smoothly, but instead go through the lower intensities before turning off - which is not very pleasant to look at... My question is therefore if you know of any way to create a more smooth fade? Below is my code so far. Note that I have had to insert specific lines at the bottom to actually turn off the leds, as setting the intensity to "0" apparently doesn't seem to do the trick - am I missing something here?
Ideally I would like to be able to dictate how long it takes for the LEDs to fade in/out.
Thanks in advance
#include <Adafruit_NeoPixel.h>
#define LED_PIN 6
#define LED_COUNT 30 // How many NeoPixels are attached to the Arduino?
#define High_Intensity 20
#define Low_Intensity 1
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit... if you must, connect GND first.
void setup() {
strip.begin();
strip.show(); // initialize all pixels to "off"
}
void loop() {
brighten();
darken();
}
// 0 to 255
void brighten() {
uint16_t i, j;
for (j = Low_Intensity; j < High_Intensity; j++) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, j, 0, 0);
}
strip.show();
delay(50);
}
delay(500);
}
// 255 to 0
void darken() {
Serial.begin(9600);
uint16_t i, j;
for (j = High_Intensity; j > 1; j--) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, j, 0, 0);
}
strip.show();
delay(100);
Serial.println(j);
}
// Turn leds back off
for(int i=0; i<60; i++) {
strip.setPixelColor(i, 0);
strip.show();}
delay(5000);
}
Regarding the off-topic part (I won't go into detail)
The capacitor between the power leads will protect the Neopixels controller from sudden voltage changes due to the fact that each pixel drives their leds with PWM.
The resistor terminates the communication lines which reduces reflections in the wires.
Both improve performance and reduce risk of damage to the pixels. Hence you should use them. Just make sure you use them on the correct pins. There's plenty of information online on how to properly control Neopixel strings.
(I should note that I see many suggestions placing a resistor in front
of the LED strip and a capacitor on the power supply - will this
affect intensity?)
This will not affect intensity! Intensity is only controlled by the pixels' pwm signal and the supplied current.
Programming-wise:
As I understand the Neopixel library, maximum light intensity has a
value of 255.
Yes brightness is controlled by 3 values, red, green and blue each ranging from 0 (off) to 255 (max brightness). It's the duty cycle of the led's color channel.
This gives you a brightness resolution of 256 values over the entire brightness range. (8 bit).
My question is therefore if you know of any way to create a more
smooth fade?
This causes a problem. If you want to operate in a lower brightness range you only have a very limited number of steps to fade through.
So what if we reduce the current that supplies the leds?
As control and led supply voltage are usually supplied through the same rail there is no way to dim the entire strip while keeping the 8-bit resolution.
To control the fading time alter the delay time between each value update. Keep in mind the limited dynamic and persistence of human vision. Any visible brightness change that happens < 30Hz will cause a noticable step.
Below is my code so far. Note that I have had to insert specific lines
at the bottom to actually turn off the leds, as setting the intensity
to "0" apparently doesn't seem to do the trick - am I missing
something here?
for (j = High_Intensity; j > 1; j--)
In the loop that darkens the strip you run the loop while j > 1. So the last brightness value you set is 2 which obviously isn't 0.
for (j = High_Intensity; j > -1; j--)
should do the trick.

Need help displaying serial monitor on LCD

I'm having issues displaying the serial monitor on an lcd. I am not getting any error and the LCD is lit up so I don't think I wired it wrong. I am able to open up the serial monitor/plotter and see in information changing so my other component is also working so the problem must be in the code...
#include <LiquidCrystal.h>
/**
* LIDARLite I2C Example
* Author: Garmin
* Modified by: Shawn Hymel (SparkFun Electronics)
* Date: June 29, 2017
*
* Read distance from LIDAR-Lite v3 over I2C
*
* See the Operation Manual for wiring diagrams and more information:
* http://static.garmin.com/pumac/LIDAR_Lite_v3_Operation_Manual_and_Technical_Specifications.pdf
*/
#include <Wire.h>
#include <LIDARLite.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
// Globals
LIDARLite lidarLite;
int cal_cnt = 0;
void setup()
{
Serial.begin(9600); // Initialize serial connection to display distance readings
lidarLite.begin(0, true); // Set configuration to default and I2C to 400 kHz
lidarLite.configure(0); // Change this number to try out alternate configurations
lcd.begin(16, 2);
// initialize the serial communications:
}
void loop()
{
int dist;
// At the beginning of every 100 readings,
// take a measurement with receiver bias correction
if ( cal_cnt == 0 ) {
dist = lidarLite.distance(); // With bias correction
} else {
dist = lidarLite.distance(false); // Without bias correction
}
// Increment reading counter
cal_cnt++;
cal_cnt = cal_cnt % 100;
// Display distance
Serial.print(dist);
Serial.println(" cm");
delay(10);
// when characters arrive over the serial port...
if (Serial.available()) {
// wait a bit for the entire message to arrive
delay(100);
// clear the screen
lcd.clear();
// read all the available characters
while (Serial.available() > 0) {
// display each character to the LCD
lcd.write(Serial.read());
}
}
}
The LCD should be displaying the changing measurements
The LCD is lit up and I can adjust the back light but I can't get anything to show up.
Just because the LCD is "lit" doesn't mean it's wired correctly. In fact, the backlighting circuit is usually totally separate from the data and control signals circuits. I would start by checking the assumption that it's wired correctly with a simple command to print a known value to the LCD:
lcd.clear();
lcd.println("TEST");
If this works, then you know the LCD is working and can look elsewhere for the problem.
If this doesn't work, I'd question your assumption that it's hooked up correctly, but if you still get nothing but "blue blocks" then it might be something as simple as your contrast is not correct. It can be tricky getting the contrast and brightness to a good combination for readability. See if your display has a small potentiometer (usually adjustable with a very small Philips-head driver) on the back and carefully adjust the contrast.
Brightness is often changeable through software commands but most LCDs default to high brightness when first booted up.
If changing contrast doesn't work, you may have a real wiring problem and then it really is off-topic for this forum. In that case you should sketch a schematic and post on Electrical Engineering stack.

LED strip not working

we are still having trouble with our LED strip. We fixed the library issue, and are now trying to program the LED's but have run into a few issues.
1) First of all, our LED strip does not consistently light up. We are using a 12v battery and everything is wired correctly, but how the LED's appear is very inconsistent. Not all of them light up, they are all different colors, and are all of varying brightness. We have tried to resolve this by just powering it with the battery, using our arduino as a power supply, and added a 1000uf capacitor to make sure the strip doesnt get a surge of power and short the strip. Our code is this:
/* Arduino Tutorial - How to use an RGB LED Strip
Dev: Michalis Vasilakis // Date 3/6/2016 // Ver 1.0
Info: www.ardumotive.com */
//Library
#include <Adafruit_NeoPixel.h>
//Constants
const int dinPin = 4; // Din pin to Arduino pin 4
const int numOfLeds = 10; // Number of leds
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(numOfLeds, dinPin, NEO_GRB + NEO_KHZ800);
// Color takes RGB values, from 0,0,0 up to 255,255,255
// e.g. White = (255,255,255), Red = (255,0,0);
int red = 255; //Value from 0(led-off) to 255().
int green = 0;
int blue = 0;
void setup() {
pixels.begin(); // Initializes the NeoPixel library
pixels.setBrightness(100); // Value from 0 to 100%
}
void loop() {
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
for(int i=0;i<numOfLeds;i++){
pixels.setPixelColor(i, pixels.Color(red,green,blue));
pixels.show(); // This sends the updated pixel color to the hardware.
delay(10); // Delay for a period of time to change the next led
}
}
We are trying to set all the LED's to red just to test the code, but nothing is working. Has anyone experienced this before or has any idea of what is not working?
99% of the time this happens when you haven't tied the ground of the LED strip to the ground of the Arduino and the ground of the power supply.

Resources