Help Adding an LED Pixel ring to my timer

Hi There! Newb here. I'm looking for a bit of help.

I have a neo pixel ring that I want to pulsate with a decrementing timer but i'm having trouble adding it in to my project. For context, I buttons set up on my breadboard which are allowing input into an LCD to view the remaining time. The timer works fine.

Can anyone give me some guidance as to how I would go about adding the pixel ring pulsate with the timer and remain on when the timer hits zero?

Im using the libraries:
#include <Adafruit_NeoPixel.h>
#include "Countimer.h"

Any assistance is greatly appreciated.

Welcome to the forum

Start by posting your current code, using code tags when you do

//Jay Royal

//Accelerometer library
#include <MPU6050_tockn.h>
#include <Wire.h>
MPU6050 mpu6050(Wire);

//Neopixel LED library and I/O
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUM_LEDS 16
Adafruit_NeoPixel strip(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

//Timer Library
#include "Countimer.h"
Countimer tdown;

//LCD library, Memory and I/O
#include <LiquidCrystal.h>
#include <EEPROM.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
#define bt_set A3
#define bt_up A2
#define bt_down A1
#define bt_start A0

//Time Variables in minutes and Seconds
int time_s = 0;
int time_m = 0;

//Flags for buttons? I dont really understand
int set = 1;  // was 0
int flag1 = 0, flag2 = 0;

//Pause and accelerometer variables
bool isPaused = false;              // Flag to indicate whether the timer is paused or not
bool passedAccelThreshold = false;  //Flag to pass accelerometer threshold

// variable to relieve pressed button
int setButtonJustPressed = HIGH;

void setup() {
  Serial.begin(9600);

  //button input locations
  pinMode(bt_set, INPUT_PULLUP);
  pinMode(bt_up, INPUT_PULLUP);
  pinMode(bt_down, INPUT_PULLUP);
  pinMode(bt_start, INPUT_PULLUP);

  // set up display
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Peripheral Timer");
  tdown.setInterval(print_time, 999);
  //eeprom_read(); //<--- not sure whether necessary
  delay(1000);
  lcd.clear();

  Wire.begin();
  mpu6050.begin();
  mpu6050.calcGyroOffsets(true);  // Calibrate gyro offsets
}

//decrements the time value and stops at 0
void print_time() {
  if (time_s > 0 || time_m > 0) {
    time_s = time_s - 1;
    if (time_s < 0) {
      time_s = 59;
      time_m = time_m - 1;
      if (time_m < 0) {
        // Reset minutes and seconds to 0 if both reach zero
        time_m = 0;
        time_s = 0;
      }
    }
  }
}

//void tdownComplete(){Serial.print("ok");}
//tdown.stop();


void loop() {

  tdown.run();       //runs timer
  mpu6050.update();  //updates gyroscope MPU6050

  // Calculate pitch angle in degrees
  float pitch = atan2(-mpu6050.getAccY(), sqrt(pow(mpu6050.getAccX(), 2) + pow(mpu6050.getAccZ(), 2))) * 180.0 / PI;

  //Play Accelerometer
  if (pitch < -80.0 && passedAccelThreshold == false) {
    tdown.start();
    Serial.println("Play!");
    passedAccelThreshold = true;
  } else if (pitch > -21.0 && pitch < 10.0) {
    passedAccelThreshold = false;
  }

  //Pause Accelerometer... Needs to be fixed to stop running over and over to serial monitor
  if (pitch > -20.0 && passedAccelThreshold == true) {
    tdown.pause();
    Serial.println("Pause!");
    passedAccelThreshold = false;
  } else if (pitch > -5.0 && pitch < 10.0) {
    passedAccelThreshold = true;
  }

  //Plays timer...
  int pressedSet = digitalRead(bt_start);
  if (pressedSet == LOW && setButtonJustPressed == HIGH) {
    Serial.println("SET pressed!");
    if (isPaused) {
      tdown.start();
    } else {
      tdown.pause();
    }
    isPaused = !isPaused;
  }
  setButtonJustPressed = pressedSet;

  //Button up for timer
  if (digitalRead(bt_up) == 0) {
    if (set == 0) {
      tdown.start();
      flag2 = 1;
    }
    if (set == 1) { time_s++; }
    if (set == 2) { time_m++; }

    if (time_s > 59) { time_s = 0; }
    if (time_m > 59) { time_m = 0; }

    if (set > 0) { eeprom_write(); }
    delay(200);
  }

  //Button down for timer
  if (digitalRead(bt_down) == 0) {
    if (set == 0) {
      tdown.stop();
      flag2 = 0;
    }
    if (set == 1) { time_s--; }
    if (set == 2) { time_m--; }
    if (time_s < 0) { time_s = 59; }
    if (time_m < 0) { time_m = 59; }
    if (set > 0) { eeprom_write(); }
    delay(200);
  }

  //button start for timer
  if (digitalRead(bt_set) == 0) {
    flag2 = 1;
    //eeprom_read();
    //tdown.restart();
    tdown.start();
  }

  //LCD Display
  lcd.setCursor(0, 0);
  if (set == 0) { lcd.print("Peripheral Timer"); }
  if (set == 1) { lcd.print("  Set Timer SS  "); }
  if (set == 2) { lcd.print("  Set Timer MM  "); }

  lcd.setCursor(5, 1);
  if (time_m <= 9) { lcd.print("0"); }
  lcd.print(time_m);
  lcd.print(":");
  if (time_s <= 9) { lcd.print("0"); }
  lcd.print(time_s);
  lcd.print("   ");

  delay(500);
}

//Timer Memory
void eeprom_write() {
  EEPROM.write(1, time_s);
  EEPROM.write(2, time_m);
}

void eeprom_read() {
  time_s = EEPROM.read(1);
  time_m = EEPROM.read(2);
}




















You will want an external power supply. Neopixels can require a lot of current... usual calculations are NUM_PIX * 20mA-per-color * 3 colors. A 16 pixel ring would be 16 * 20 * 3 = 960mA (1Amp). Also place an electrolytic capacitor across power and ground, and place a 300R resistor in-line with the data pin. Connections like this.

Thanks! You think its a risk putting the pixel rings on the same breadboard? Seemed to work fine.... oops lol.

I need help with the code in the reply above. Can you tell me what and where I need to write to get the LED ring talking with the timer?

Thanks again

The real risk is in you not knowing how to determine "risk"... so let's learn it...

Search "arduino breadboard datasheet"

You will see on one datasheet for a common breadboard, the specifications show Rated: 36V/2A

Remember (really, remember) ONE LED will use 20mA of current at its brightest.

A Neopixel has THREE LEDs (RED, GREEN, BLUE) per PIXEL.

A pixel ring with 16 neopixels will draw (16 * 20mA * 3LED/pix = 960mA) 0.96A, which is less than 50% of the rated value.

This should let you know: NO risk to the BREADBOARD.

You must have an EXTERNAL POWER SUPPLY for this amount of current in your Neopixels (plus other devices). You MUST NEVER use the Arduino to supply more than 40mA of current per pin, or 100mA current per board (multiple pins). For NO RISK, ALWAYS use an external power supply.

AND: Every question about hardware and software, should show your written program (you have that) and a wiring diagram.

What step are we on?

Next step; Writing WORKING code.

Programs should start small, with testing one device until that one device is working as you want. A great place to learning to program for the Arduino is on your IDE's Built-In Examples. (you can also search "arduino built-in examples")

FILE >> EXAMPLES >> BUILT-IN EXAMPLES >> BASICS >>
... and do many sketches from 01. Basics to 07. Display.

Your program has a (1) Neopixel, an (2) LCD and an (3) MPU6050. This is too much to learn for you right now. You should start with the LCD. It displays characters, so it should be the easiest of the three to write a working sketch.

#include <LiquidCrystal.h> // load the LCD library

LiquidCrystal lcd(7, 8, 9, 10, 11, 12); // create an LCD OBJECT and assign Arduino pins to the LCD

void setup() {
  lcd.begin(16, 2); // initialize the LCD object with sixteen columns and two rows
  lcd.print("     I live"); // send characters to the LCD
}

void loop() { } // do nothing

Your turn... write a sketch for the LCD, then one for the NeoPixel, then the MPU then the "timer." After that, making two devices work together will be the goal... then all devices.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.