Another project¶
Vimeo¶
Ricardo O Nascimento- prototyping movement from Textile Academy on Vimeo.
Youtube¶
RGB LED STRIP CODE
#include <FastLED.h>
#define LED_PIN 5
#define NUM_LEDS 27
#define BRIGHTNESS 64
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
#define UPDATES_PER_SECOND 100
// This example shows several ways to set up and use 'palettes' of colors
// with FastLED.
//
// These compact palettes provide an easy way to re-colorize your
// animation on the fly, quickly, easily, and with low overhead.
//
// USING palettes is MUCH simpler in practice than in theory, so first just
// run this sketch, and watch the pretty lights as you then read through
// the code. Although this sketch has eight (or more) different color schemes,
// the entire sketch compiles down to about 6.5K on AVR.
//
// FastLED provides a few pre-configured color palettes, and makes it
// extremely easy to make up your own color schemes with palettes.
//
// Some notes on the more abstract 'theory and practice' of
// FastLED compact palettes are at the bottom of this file.
CRGBPalette16 currentPalette;
TBlendType currentBlending;
extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
void setup() {
delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
}
void loop()
{
ChangePalettePeriodically();
static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */
FillLEDsFromPaletteColors( startIndex);
FastLED.show();
FastLED.delay(1000 / UPDATES_PER_SECOND);
}
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 255;
for( int i = 0; i < NUM_LEDS; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
colorIndex += 3;
}
}
// There are several different palettes of colors demonstrated here.
//
// FastLED provides several 'preset' palettes: RainbowColors_p, RainbowStripeColors_p,
// OceanColors_p, CloudColors_p, LavaColors_p, ForestColors_p, and PartyColors_p.
//
// Additionally, you can manually define your own color palettes, or you can write
// code that creates color palettes on the fly. All are shown here.
void ChangePalettePeriodically()
{
uint8_t secondHand = (millis() / 1000) % 60;
static uint8_t lastSecond = 99;
if( lastSecond != secondHand) {
lastSecond = secondHand;
if( secondHand == 0) { currentPalette = RainbowColors_p; currentBlending = LINEARBLEND; }
if( secondHand == 10) { currentPalette = RainbowStripeColors_p; currentBlending = NOBLEND; }
if( secondHand == 15) { currentPalette = RainbowStripeColors_p; currentBlending = LINEARBLEND; }
if( secondHand == 20) { SetupPurpleAndGreenPalette(); currentBlending = LINEARBLEND; }
if( secondHand == 25) { SetupTotallyRandomPalette(); currentBlending = LINEARBLEND; }
if( secondHand == 30) { SetupBlackAndWhiteStripedPalette(); currentBlending = NOBLEND; }
if( secondHand == 35) { SetupBlackAndWhiteStripedPalette(); currentBlending = LINEARBLEND; }
if( secondHand == 40) { currentPalette = CloudColors_p; currentBlending = LINEARBLEND; }
if( secondHand == 45) { currentPalette = PartyColors_p; currentBlending = LINEARBLEND; }
if( secondHand == 50) { currentPalette = myRedWhiteBluePalette_p; currentBlending = NOBLEND; }
if( secondHand == 55) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
}
}
// This function fills the palette with totally random colors.
void SetupTotallyRandomPalette()
{
for( int i = 0; i < 16; i++) {
currentPalette[i] = CHSV( random8(), 255, random8());
}
}
// This function sets up a palette of black and white stripes,
// using code. Since the palette is effectively an array of
// sixteen CRGB colors, the various fill_* functions can be used
// to set them up.
void SetupBlackAndWhiteStripedPalette()
{
// 'black out' all 16 palette entries...
fill_solid( currentPalette, 16, CRGB::Black);
// and set every fourth one to white.
currentPalette[0] = CRGB::White;
currentPalette[4] = CRGB::White;
currentPalette[8] = CRGB::White;
currentPalette[12] = CRGB::White;
}
// This function sets up a palette of purple and green stripes.
void SetupPurpleAndGreenPalette()
{
CRGB purple = CHSV( HUE_PURPLE, 255, 255);
CRGB green = CHSV( HUE_GREEN, 255, 255);
CRGB black = CRGB::Black;
currentPalette = CRGBPalette16(
green, green, black, black,
purple, purple, black, black,
green, green, black, black,
purple, purple, black, black );
}
// This example shows how to set up a static color palette
// which is stored in PROGMEM (flash), which is almost always more
// plentiful than RAM. A static PROGMEM palette like this
// takes up 64 bytes of flash.
const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
CRGB::Red,
CRGB::Gray, // 'white' is too bright compared to red and blue
CRGB::Blue,
CRGB::Black,
CRGB::Red,
CRGB::Gray,
CRGB::Blue,
CRGB::Black,
CRGB::Red,
CRGB::Red,
CRGB::Gray,
CRGB::Gray,
CRGB::Blue,
CRGB::Blue,
CRGB::Black,
CRGB::Black
};
Green message
FE8A75 16681589
Green 1 FF30CF 16724175
Yellow message FEA25D 16687709
Yellow 2 FF18E7 16718055
Red message FE926D 16683629
Red 3 FF7A85 16743045
Blue message FEB24D 16691789
Result 4 FF10EF 16716015
Turn on + FFA857 16754775
Turn off - FFE01F 16769055
Final Code 2
#include <IRremote.h>
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#define STRIP_PIN 4 // Define the pin for the OLED light strip
#define NUM_LEDS 108 // Define the number of LEDs in the OLED light strip
Adafruit_NeoPixel strip(NUM_LEDS, STRIP_PIN, NEO_GRB + NEO_KHZ800); // Create an instance of the OLED light strip
int RECV_PIN = 3; // Define the pin for the IR receiver sensor
IRrecv irrecv(RECV_PIN); // Create an instance of the IR receiver sensor
decode_results results; // Create a variable to store the results of the IR receiver sensor
// #include <WiFiNINA.h>
#define SCREEN_WIDTH 128 // OLED display width
#define SCREEN_HEIGHT 64 // OLED display height
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int count = 0;
int redcount = 0;
void setup() {
strip.begin(); // Initialize the OLED light strip
strip.show(); // Initialize all LEDs to 'off'
Wire.begin(); // Initialize the OLED light strip
Serial.begin(9600); // Initialize serial communication
irrecv.enableIRIn(); // Enable the IR receiver sensor
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3C for 128x64
// if the OLED init failed, loop forever:
Serial.print("hello");
for(;;); // Don't proceed, loop forever
}
if (!display1.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x64
// if the OLED init failed, loop forever:
for(;;); // Don't proceed, loop forever
}
// // Clear the buffer
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.println("Setup");
display.display();
delay(1000);
display.clearDisplay();
display.setCursor(0, 0);
// // Clear the buffer
display1.clearDisplay();
display1.setTextSize(2); // Normal 1:1 pixel scale
display1.setTextColor(WHITE); // Draw white text
display1.setCursor(0, 0); // Start at top-left corner
display1.println("Setup");
display1.display();
delay(1000);
display1.clearDisplay();
display1.setCursor(0, 0);
}
void loop() {
display.clearDisplay();
display.setTextSize(7); // Increase text size
display.setTextColor(WHITE); // Draw white text
display1.clearDisplay();
display1.setTextSize(7); // Increase text size
display1.setTextColor(WHITE); // Draw white text
String countString = String(count); // Convert the count to a String to get its length
// Calculate center position of the text. Each character is 6 pixels wide at text size 1.
// It grows with the text size.
int textWidth = countString.length() * 6 * 7; // In pixels
int centerPosition = (SCREEN_WIDTH - textWidth) / 2;
display.setCursor(centerPosition, 0); // Position the text at the center
display.println(count);
display.display();
display1.setCursor(centerPosition, 0); // Position the text at the center
display1.println(redcount);
display1.display();
if (irrecv.decode(&results)) { // Check if the IR receiver sensor has received a signal
Serial.println(results.value, HEX); // Print the value of the signal in hexadecimal to the serial monitor
Serial.println(results.value); // Print the value of the signal in hexadecimal to the serial monitor
irrecv.resume(); // Resume the IR receiver sensor to receive the next signal
if (results.value==16724175)
{
Serial.println("green");
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0, 255, 0); // Set each LED to yellow color
}
strip.show(); // Display the yellow color on the OLED light strip
count++;
}
else if (results.value==16718055)
{
Serial.println("blue");
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0, 0, 255); // Set each LED to yellow color
}
strip.show(); // Display the yellow color on the OLED light strip
}
else if (results.value==16743045)
{
redcount++;
Serial.println("red");
Serial.println(redcount);
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 255, 0, 0); // Set each LED to red color
}
strip.show(); // Display the red color on the OLED light strip
}
else if (results.value==16769055)
{
redcount=0;
count=0;
Serial.println("clear");
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0, 0, 0); // Set each LED to red color
}
strip.show(); // Display the red color on the OLED light strip
}
else if (results.value==16716015)
{
Serial.println("result");
for(int i=0; i<10; i++){
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0, 255, 0); // Set each LED to red color
}
strip.show(); // Display the red color on the OLED light strip
delay(200);
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 255, 0, 0); // Set each LED to red color
}
strip.show(); // Display the red color on the OLED light strip
delay(200);
}
if (count>redcount){
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0, 255, 0); // Set each LED to green color
}
strip.show(); // Display the red color on the OLED light strip
}
else{
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 255, 0, 0); // Set each LED to green color
}
strip.show(); // Display the red color on the OLED light strip
}
}
}
}
SCREEN COUNT CODE
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#include <WiFiNINA.h>
#define SCREEN_WIDTH 128 // OLED display width
#define SCREEN_HEIGHT 64 // OLED display height
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int count = 0;
void setup() {
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x64
// if the OLED init failed, loop forever:
for(;;); // Don't proceed, loop forever
}
// Clear the buffer
display.clearDisplay();
display.setTextSize(2); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.println("Setup");
display.display();
delay(1000);
display.clearDisplay();
display.setCursor(0, 0);
}
void loop() {
display.clearDisplay();
display.setTextSize(7); // Increase text size
display.setTextColor(WHITE); // Draw white text
String countString = String(count); // Convert the count to a String to get its length
// Calculate center position of the text. Each character is 6 pixels wide at text size 1.
// It grows with the text size.
int textWidth = countString.length() * 6 * 7; // In pixels
int centerPosition = (SCREEN_WIDTH - textWidth) / 2;
// Ensuring we only print up to two-digit numbers in this loop
if(count > 99) {
count = 0;
}
display.setCursor(centerPosition, 0); // Position the text at the center
display.println(count);
display.display();
count++;
delay(1000); // wait for a second
}
OLED Strip green light
#include <Adafruit_NeoPixel.h>
#define STRIP_PIN 6 // Define the pin for the OLED light strip
#define NUM_LEDS 30 // Define the number of LEDs in the OLED light strip
Adafruit_NeoPixel strip(NUM_LEDS, STRIP_PIN, NEO_GRB + NEO_KHZ800); // Create an instance of the OLED light strip
void setup() {
strip.begin(); // Initialize the OLED light strip
strip.show(); // Initialize all LEDs to 'off'
}
void loop() {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0, 255, 0); // Set each LED to green color
}
strip.show(); // Display the green color on the OLED light strip
}
OLED Strip red light
#include <Adafruit_NeoPixel.h>
#define STRIP_PIN 6 // Define the pin for the OLED light strip
#define NUM_LEDS 30 // Define the number of LEDs in the OLED light strip
Adafruit_NeoPixel strip(NUM_LEDS, STRIP_PIN, NEO_GRB + NEO_KHZ800); // Create an instance of the OLED light strip
void setup() {
strip.begin(); // Initialize the OLED light strip
strip.show(); // Initialize all LEDs to 'off'
}
void loop() {
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 255, 0, 0); // Set each LED to green color
}
strip.show(); // Display the green color on the OLED light strip
}
IR Reciever
#include <IRremote.h>
int RECV_PIN = 7; // Define the pin for the IR receiver sensor
IRrecv irrecv(RECV_PIN); // Create an instance of the IR receiver sensor
decode_results results; // Create a variable to store the results of the IR receiver sensor
void setup() {
Serial.begin(9600); // Initialize serial communication
irrecv.enableIRIn(); // Enable the IR receiver sensor
}
void loop() {
if (irrecv.decode(&results)) { // Check if the IR receiver sensor has received a signal
Serial.println(results.value, HEX); // Print the value of the signal in hexadecimal to the serial monitor
Serial.println(results.value); // Print the value of the signal in hexadecimal to the serial monitor
irrecv.resume(); // Resume the IR receiver sensor to receive the next signal
}
}
#include <IRremote.h>
int RECV_PIN = 7; // Define the pin for the IR receiver sensor
IRrecv irrecv(RECV_PIN); // Create an instance of the IR receiver sensor
decode_results results; // Create a variable to store the results of the IR receiver sensor
void setup() {
Serial.begin(9600); // Initialize serial communication
irrecv.enableIRIn(); // Enable the IR receiver sensor
}
void loop() {
if (irrecv.decode(&results)) { // Check if the IR receiver sensor has received a signal
Serial.println(results.value, HEX); // Print the value of the signal in hexadecimal to the serial monitor
Serial.println(results.value); // Print the value of the signal in hexadecimal to the serial monitor
irrecv.resume(); // Resume the IR receiver sensor to receive the next signal
if (results.value==16724175)
{
Serial.println("green");
}
}
}
Final Code
#include <IRremote.h>
#include <Adafruit_NeoPixel.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <SPI.h>
#define STRIP_PIN 4 // Define the pin for the OLED light strip
#define NUM_LEDS 108 // Define the number of LEDs in the OLED light strip
Adafruit_NeoPixel strip(NUM_LEDS, STRIP_PIN, NEO_GRB + NEO_KHZ800); // Create an instance of the OLED light strip
int RECV_PIN = 3; // Define the pin for the IR receiver sensor
IRrecv irrecv(RECV_PIN); // Create an instance of the IR receiver sensor
decode_results results; // Create a variable to store the results of the IR receiver sensor
// #include <WiFiNINA.h>
#define SCREEN_WIDTH 128 // OLED display width
#define SCREEN_HEIGHT 64 // OLED display height
// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Adafruit_SSD1306 display1(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int count = 0;
int redcount = 0;
void setup() {
strip.begin(); // Initialize the OLED light strip
strip.show(); // Initialize all LEDs to 'off'
Wire.begin(); // Initialize the OLED light strip
Serial.begin(9600); // Initialize serial communication
irrecv.enableIRIn(); // Enable the IR receiver sensor
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3D)) { // Address 0x3C for 128x64
// if the OLED init failed, loop forever:
Serial.print("hello");
for(;;); // Don't proceed, loop forever
}
if (!display1.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x64
// if the OLED init failed, loop forever:
for(;;); // Don't proceed, loop forever
}
// // Clear the buffer
display.clearDisplay();
display.setTextSize(1); // Normal 1:1 pixel scale
display.setTextColor(SSD1306_WHITE); // Draw white text
display.setCursor(0, 0); // Start at top-left corner
display.println("Setup");
display.display();
delay(1000);
display.clearDisplay();
display.setCursor(0, 0);
// // Clear the buffer
display1.clearDisplay();
display1.setTextSize(2); // Normal 1:1 pixel scale
display1.setTextColor(WHITE); // Draw white text
display1.setCursor(0, 0); // Start at top-left corner
display1.println("Setup");
display1.display();
delay(1000);
display1.clearDisplay();
display1.setCursor(0, 0);
}
void loop() {
display.clearDisplay();
display.setTextSize(7); // Increase text size
display.setTextColor(WHITE); // Draw white text
display1.clearDisplay();
display1.setTextSize(7); // Increase text size
display1.setTextColor(WHITE); // Draw white text
String countString = String(count); // Convert the count to a String to get its length
// Calculate center position of the text. Each character is 6 pixels wide at text size 1.
// It grows with the text size.
int textWidth = countString.length() * 6 * 7; // In pixels
int centerPosition = (SCREEN_WIDTH - textWidth) / 2;
display.setCursor(centerPosition, 0); // Position the text at the center
display.println(count);
display.display();
display1.setCursor(centerPosition, 0); // Position the text at the center
display1.println(redcount);
display1.display();
if (irrecv.decode(&results)) { // Check if the IR receiver sensor has received a signal
Serial.println(results.value, HEX); // Print the value of the signal in hexadecimal to the serial monitor
Serial.println(results.value); // Print the value of the signal in hexadecimal to the serial monitor
irrecv.resume(); // Resume the IR receiver sensor to receive the next signal
if (results.value==16724175)
{
Serial.println("green");
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0, 255, 0); // Set each LED to yellow color
}
strip.show(); // Display the yellow color on the OLED light strip
count++;
}
else if (results.value==16718055)
{
Serial.println("blue");
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0, 0, 255); // Set each LED to yellow color
}
strip.show(); // Display the yellow color on the OLED light strip
}
else if (results.value==16743045)
{
redcount++;
Serial.println("red");
Serial.println(redcount);
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 255, 0, 0); // Set each LED to red color
}
strip.show(); // Display the red color on the OLED light strip
}
else if (results.value==16769055)
{
redcount=0;
count=0;
Serial.println("clear");
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0, 0, 0); // Set each LED to red color
}
strip.show(); // Display the red color on the OLED light strip
}
else if (results.value==16716015)
{
Serial.println("result");
for(int i=0; i<10; i++){
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0, 255, 0); // Set each LED to red color
}
strip.show(); // Display the red color on the OLED light strip
delay(200);
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 255, 0, 0); // Set each LED to red color
}
strip.show(); // Display the red color on the OLED light strip
delay(200);
}
if (count>redcount){
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 0, 255, 0); // Set each LED to green color
}
strip.show(); // Display the red color on the OLED light strip
}
else{
for (int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, 255, 0, 0); // Set each LED to green color
}
strip.show(); // Display the red color on the OLED light strip
}
}
}
}
Last update:
July 31, 2023