I am building a music stand lamp. There are buttons to increment the brightness 0-1 in 0.1 steps (circular) and a button to circle through Off, white, R,G & B
There’s a Lipo charging backpack but I’m confident that’s fine (worked on a previous project)
My code compiles and uploads (using USBtinyISP
) on an Adafruit Trinket (ATtiny85 16MHz 5V) but the LED doesn’t come on (it starts off) but the buttons have no effect. Can you see glaring errors in my code? LEDs are wired OK because the previous project had them lit and I’ve not changed the wiring or pin numbering
I can’t debug using the monitor in Arduino IDE because the card doesn’t have the native tech. (USB, I think?? Seems to be why it needs a ‘programmer’)
The momentary press buttons are connected to ground and #0 & #1
The Neopixel strip is connected to Ground, 5V and data to #2
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include <EasyButton.h>
#include <avr/power.h>
#include <avr/sleep.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define COLOR_BUTTON_PIN 0 // button to cycle through OFF/WHITE/RED/GREEN/BLUE
#define BRIGHTNESS_BUTTON_PIN 1 // button to increment brightness factor from 0.1 to 1 in increments of 0.1
#define PIXEL_PIN 2 // Digital IO pin connected to the NeoPixels.
#define PIXEL_COUNT 29 // Number of NeoPixels
// Buttons.
EasyButton COLOR_BUTTON(COLOR_BUTTON_PIN);
EasyButton BRIGHTNESS_BUTTON(BRIGHTNESS_BUTTON_PIN);
// Declare NeoPixel strip object:
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
// button variables
float bright = 0.1; // brightness factor
int col = 0; // Currently-active colour index on colour array (of lightCol objects)
class lightCol { //Class describing colours in RGB values
public:
int rr;
int gg;
int bb;
lightCol() {} // This SEEMS to be superfluous but the compile fails without it. Looks like a content-free version of the lines directly below??
lightCol(uint8_t red, uint8_t grn, uint8_t blu) {
rr = red;
gg = grn;
bb = blu;
}
};
lightCol colour[5]; //declare an array of 5 lightCol objects (Off, White, Red, Green & Blue added in setup)
// Callback for the brightness button.
void onBrightnessPressed() {
bright += 0.1;
if(bright > 1) {bright = 0;} // Advance to next brightness level, wrap around after #1
renewStrip(bright, col);
}
// Callback for the colour change button.
void onColourPressed() {
if(++col > 4) col = 0; // Advance to next mode, wrap around after #4
renewStrip(bright, col);
}
void renewStrip(float b, int c){ //b=brightness factor from 0.1 to 1 & c = index to colour array, containing colour objects (RGB values)
for (int pixel = 0; pixel < strip.numPixels(); pixel++){
// strip.Colour(R,G,B) converts the three uint8_t RGB values in the indexed colour array into a combined colour value for strip.Color
strip.setPixelColor(pixel, strip.Color(colour[c].rr*b, colour[c].gg*b, colour[c].bb*b)); strip.show();
}
}
void setup() {
// Set up the IO pins
pinMode(COLOR_BUTTON_PIN, INPUT_PULLUP);
pinMode(BRIGHTNESS_BUTTON_PIN, INPUT_PULLUP);
pinMode(PIXEL_PIN, OUTPUT);
// Initialize the buttons.
COLOR_BUTTON.begin();
BRIGHTNESS_BUTTON.begin();
// Attach callbacks.
BRIGHTNESS_BUTTON.onPressed(onBrightnessPressed);
COLOR_BUTTON.onPressed(onColourPressed);
// define the values in the colour array
colour[0] = lightCol(0, 0, 0); //OFF
colour[1] = lightCol(255, 255, 255); //WHITE
colour[2] = lightCol(255, 0, 0); //RED
colour[3] = lightCol(0, 255, 0); //GREEN
colour[4] = lightCol(0, 0, 255); //BLUE
strip.begin(); // Initialize NeoPixel strip object (REQUIRED)
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
// cycle round and call the appropriate callback if a button is pressed. Otherwise, do nothing.
COLOR_BUTTON.read();
BRIGHTNESS_BUTTON.read();
}
It seems to upload fine but there are a couple of notable lines in the compile but I don’t know if they’re potentially relevant
Compiling core...
Using precompiled core: /tmp/arduino/cores/adafruit_avr_trinket5_abf884fb34cc4d872f836bd18adcd386/core.a
Linking everything together...
/home/greg/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-gcc -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=attiny85 -o /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/MusicStandLamp-v3.ino.elf /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/sketch/MusicStandLamp-v3.ino.cpp.o /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/libraries/Adafruit_NeoPixel/Adafruit_NeoPixel.cpp.o /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/libraries/Adafruit_NeoPixel/esp.c.o /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/libraries/Adafruit_NeoPixel/esp8266.c.o /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/libraries/Adafruit_NeoPixel/kendyte_k210.c.o /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/libraries/EasyButton/EasyButton.cpp.o /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/libraries/EasyButton/EasyButtonBase.cpp.o /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/libraries/EasyButton/EasyButtonTouch.cpp.o /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/libraries/EasyButton/EasyButtonVirtual.cpp.o /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/libraries/EasyButton/Sequence.cpp.o /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/../../cores/adafruit_avr_trinket5_abf884fb34cc4d872f836bd18adcd386/core.a -L/tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468 -lm
In function 'INT1_vect':
/home/greg/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/WInterrupts.c:373:1: warning: 'INT1_vect' appears to be a misspelled 'signal' handler, missing '__vector' prefix [-Wmisspelled-isr]
/home/greg/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/MusicStandLamp-v3.ino.elf /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/MusicStandLamp-v3.ino.eep
/home/greg/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-objcopy -O ihex -R .eeprom /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/MusicStandLamp-v3.ino.elf /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/MusicStandLamp-v3.ino.hex
IMPLEMENT_ISR(INT1_vect, EXTERNAL_INT_1)
^
In function 'INT1_vect':
/home/greg/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/arduino/WInterrupts.c:373:1: warning: 'INT1_vect' appears to be a misspelled 'signal' handler, missing '__vector' prefix [-Wmisspelled-isr]
IMPLEMENT_ISR(INT1_vect, EXTERNAL_INT_1)
^
Using library Adafruit NeoPixel at version 1.12.2 in folder: /home/greg/Arduino/libraries/Adafruit_NeoPixel
Using library EasyButton at version 2.0.3 in folder: /home/greg/Arduino/libraries/EasyButton
/home/greg/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/bin/avr-size -A /tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/MusicStandLamp-v3.ino.elf
Sketch uses 4934 bytes (92%) of program storage space. Maximum is 5310 bytes.
Global variables use 316 bytes of dynamic memory.
"/home/greg/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude" "-C/home/greg/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf" -v -pattiny85 -cusbtiny "-Uflash:w:/tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/MusicStandLamp-v3.ino.hex:i"
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "/home/greg/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
User configuration file is "/home/greg/.avrduderc"
User configuration file does not exist or is not a regular file, skipping
Using Port : usb
Using Programmer : usbtiny
avrdude: usbdev_open(): Found USBtinyISP, bus:device: 001:056
AVR Part : ATtiny85
Chip Erase delay : 400000 us
PAGEL : P00
BS2 : P00
RESET disposition : possible i/o
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom 65 12 4 0 no 512 4 0 4000 4500 0xff 0xff
flash 65 6 32 0 yes 8192 64 128 30000 30000 0xff 0xff
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
lock 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
efuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
Programmer Type : USBtiny
Description : USBtiny simple USB programmer, https://learn.adafruit.com/usbtinyisp
avrdude: programmer operation not supported
avrdude: Using SCK period of 10 usec
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.00s
avrdude: Device signature = 0x1e930b (probably t85)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: Using SCK period of 10 usec
avrdude: reading input file "/tmp/arduino/sketches/58CB08F030B315F2AC356DF86DB6B468/MusicStandLamp-v3.ino.hex"
avrdude: writing flash (4934 bytes):