Programming LED's (Arduino itsy bitsy m4 express)

Hi all, inexperienced programmer here at your service (hehe)

I am currently researching about setting up LED lights on our FRC Robot. It is a Arduino itsy bitzy m4 express using it to control the LED’s. I was wondering if anyone knew any documentation on it because I am having an hard time finding it.

some spoilers: It is to act as an break light.

I have been coding the lights for the past two years, but the computer that has all the code is not with me… oof. I will post the moment I get it! What LED’s are you using, and do you have the right libraries set up and everything?

I’m currently just trying to research about this. For what I am understanding, everything is getting setup but I do not have the code for it yet, hence why I’m researching now beforehand

edit: But can i code this in Java? because I am seeing people coding this in Arduino IDE

1 Like

Got it. I will post the code we have the moment we get it. The code is for a Leonardo, but it should work on any arduino. Are you going to be using a LED strip? That is what the code is for, so I was wondering if it would even be helpful.

Yes, we plan on using an LED strip. We have code already for blue, red, etc setup, but we need a new “led controller” to use for the special project “brakelight”

Our team this year is using the RoborRio to control the lights. This makes it faster and you can have unlimited options.

What LED strips do you have? If you use WS2812 compatible strips, you can control them directly from the roboRIO, no Arduino needed.
https://docs.wpilib.org/en/latest/docs/software/actuators/addressable-leds.html

Yeah this is my first year of programming (actually like 6 months), and I believe we might use the RoboRio but as an noob, I’m not quite sure.

Ok, I do recognize Addressable LED’s. That answers my question for if I would need to usse Arduino IDE, thanks!

Here is our testing code we used for the roborio. Obviously we are not going to keep this in the main robot.java, but for a test, it workes.
/----------------------------------------------------------------------------/
/* Copyright © 2019 FIRST. All Rights Reserved. /
/
Open Source Software - may be modified and shared by FRC teams. The code /
/
must be accompanied by the FIRST BSD license file in the root directory of /
/
the project. */
/----------------------------------------------------------------------------/
package edu.wpi.first.wpilibj.examples.addressableled;
import edu.wpi.first.wpilibj.AddressableLED;
import edu.wpi.first.wpilibj.AddressableLEDBuffer;
import edu.wpi.first.wpilibj.TimedRobot;
public class Robot extends TimedRobot {
private AddressableLED m_led;
private AddressableLEDBuffer m_ledBuffer;
// Store what the last hue of the first pixel is
private int m_rainbowFirstPixelHue;
@Override
public void robotInit() {
// PWM port 9
// Must be a PWM header, not MXP or DIO
m_led = new AddressableLED(9);
// Reuse buffer
// Default to a length of 60, start empty output
// Length is expensive to set, so only set it once, then just update data
m_ledBuffer = new AddressableLEDBuffer(60);
m_led.setLength(m_ledBuffer.getLength());
// Set the data
m_led.setData(m_ledBuffer);
m_led.start();
}
@Override
public void robotPeriodic() {
// Fill the buffer with a rainbow
rainbow();
// Set the LEDs
m_led.setData(m_ledBuffer);
}
private void rainbow() {
// For every pixel
for (var i = 0; i < m_ledBuffer.getLength(); i++) {
// Calculate the hue - hue is easier for rainbows because the color
// shape is a circle so only one value needs to precess
final var hue = (m_rainbowFirstPixelHue + (i * 180 / m_ledBuffer.getLength())) % 180;
// Set the value
m_ledBuffer.setHSV(i, hue, 255, 128);
}
// Increase by to make the rainbow “move”
m_rainbowFirstPixelHue += 3;
// Check bounds
m_rainbowFirstPixelHue %= 180;
}
}

Ok, I’m going to mess around with this and researching, thanks for the help!

No problem! I got the arduino code if you still want to look at it.

That would help me a lot, please post, thanks!

1 Like

K! Just give my programming partner a moment to send it too me. It should be here soon.

1 Like

Ok here goes! This was my partner who is still learning, so the smoothColor(); doesn’t work yet. The teamWheel() workes and is pretty cool. You can use that if you wan’t.

#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h>
#endif
#include <SoftwareSerial.h>
#define PIN 7
// 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)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRBW + NEO_KHZ800);
const int rioPin0 = 3;
const int rioPin1 = 4;
const int rioPin2 = 5;
int digIn = 0;
bool isblue = false;
uint8_t count = 0;
int i = 0;
void setup() {
// put your setup code here, to run once:
pinMode(rioPin0, INPUT);
pinMode(rioPin1, INPUT);
pinMode(rioPin2, INPUT);
strip.begin();
strip.show();
}
void loop() {
// put your main code here, to run repeatedly:
// If you make digIn = to (digitalRead(rioPin2)<< 2) | (digitalRead(rioPin1)<< 1) | digitalRead(rioPin0); it will take the input to those pins. This is how you get the info. The digIn was just set to 1 to test.
digIn =1;

switch (digIn) {
case 0:
smoothColor(10);
break;
case 1:
setFullColor(strip.Color(0, 255, 0));
delay(100);
break;
case 2:
setFullColor(strip.Color(0, 0, 255));
delay(100);
break;
case 3:
colorWipe(strip.Color(255, 0, 0), 10);
setFullColor(strip.Color(0, 0, 0));
break;
case 4:
colorWipe(strip.Color(0, 255, 0), 10);
setFullColor(strip.Color(0, 0, 0));
break;
case 5:
colorWipe(strip.Color(0, 0, 255), 10);
setFullColor(strip.Color(0, 0, 0));
break;
case 6:
colorWipe(strip.Color(255, 255, 0), 10);
setFullColor(strip.Color(0, 0, 0));
break;
case 7:
colorWipe(strip.Color(255, 255, 255), 10);
setFullColor(strip.Color(0, 0, 0));
break;
default:
teamWheel(20, 5);
break;
}
}
void teamWheel(uint8_t wait, uint16_t colorAmount) {
//Serial.print(“starting wheel”);
for (uint16_t i=strip.numPixels()-1; i>0; i–) {
strip.setPixelColor(i, strip.getPixelColor(i-1));
}
uint32_t color = strip.Color(255, 125, 0);
if (isblue) {
color = strip.Color(0, 0, 200 );
}
strip.setPixelColor(0, color);
count++;
if (count >=colorAmount){
count = 0;
isblue = !isblue;
}
strip.show();
delay(wait);
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void setFullColor(uint32_t c) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
//strip.show();
}
strip.show();
// you need strip.show(); if you want the LED’s to turn on at all.
}
void smoothColor(uint32_t color) {
for (uint32_t i=0; i>225; i++){
setFullColor(strip.Color(i, 0, 0));
strip.show();
delay (color);
}
for(uint32_t i=0; i>225; i++){
setFullColor(strip.Color(255, i, 0));
strip.show();
delay(color);
}
for(uint32_t i=255; i<0; i–){
setFullColor(strip.Color(i, 255, 0));
strip.show();
delay(color);
}
for(uint32_t i=255; i<0; i–){
setFullColor(strip.Color(0, i, 0));
strip.show();
delay(color);
}
}

Wow, I’ll look into it, Thanks so much!

No prob! Just ask if you got any questions. We have more code if you want some more examples.