The following core, libraries and driver for DigiSpark ATTiny85 need to be installed in this project:

ATTinyCore.

Digistump Driver.

Arduino tinySPI Library.

AnalogButtons.

SPI Connections:

⦾ DigiSpark ATTiny85 PB0 to TPIC6B595N Pin 12 (RCK — LATCH PIN).

⦾ DigiSpark ATTiny85 PB1 to TPIC6B595N Pin 3 (SER IN — DATA IN).

⦾ DigiSpark ATTiny85 PB2 to TPIC6B595N Pin 13(SRCK — CLOCK PIN).

⦾ TPIC6B595N Enable Pin (OE) to Ground.

The DigiSpark ATTiny85 code is shown below:

#include 
#include 

// Pin Definitions
const int
    LATCH_PIN(0),
    DATA_PIN(1),
    CLOCK_PIN(2),
    ROW_0(3),
    ROW_1(4);

//Analog Button DigiSpark ATTiny85 PB5/A0
#define ANALOG_PIN A0
AnalogButtons analogButtons(ANALOG_PIN, INPUT);
Button ButtonMode = Button(728, &ModeClick, &ModeHold, 3000);
int ClickCounter = 0;
int HoldCounter =0;

// B.A.M Parameters
byte red[4][2];
byte green[4][2];
byte blue[4][2];
int row=0, BAM_Bit, BAM_Counter=0; 

// Color-wheel Parameters
#define BAM_RESOLUTION        4  
#define COLOUR_WHEEL_LENGTH   64
uint8_t colourR[COLOUR_WHEEL_LENGTH];
uint8_t colourG[COLOUR_WHEEL_LENGTH];
uint8_t colourB[COLOUR_WHEEL_LENGTH];
int16_t ColPos = 0;
uint16_t colourPos;
uint8_t R, G, B;
#define myPI      3.14159265358979323846
#define myDPI     1.2732395
#define myDPI2    0.40528473

void setup()
{
  row = 0;
  SPI.begin();
  pinMode(ROW_0, OUTPUT);
  pinMode(ROW_1, OUTPUT);
  pinMode(LATCH_PIN, OUTPUT);
  digitalWrite(LATCH_PIN, HIGH);
  noInterrupts();
  // Clear registers
  TCNT1 = 0;
  TCCR1 = 0;
  // 15 x 3.636 = 54.54us
  OCR1C = 15;
  // Interrupt COMPA
  OCR1A = OCR1C;
  // CTC
  TCCR1 |= (1  myPI){
    x -= 2*myPI; 
    g = 1;
  }
  while(!g&(x  0; in_ >>= 1){
    d++;
  }  
  for(int16_t i = 0; i 0?(in):-(in);
} 

void fill_colour_wheel(void) 
{
  float red, green, blue;
  float c, s;
  int32_t phase = 0;
  int16_t I = 0;
  while (phase = (1 + I)*COLOUR_WHEEL_LENGTH / 3) 
      I++;
  }
}

void get_colour(int16_t p, uint8_t *R, uint8_t *G, uint8_t *B)
{
  if (p >= COLOUR_WHEEL_LENGTH)
  p -= COLOUR_WHEEL_LENGTH;
  *R = colourR[p];
  *G = colourG[p];
  *B = colourB[p];
}

It has 10 working modes selected by the Click and Hold features of the AnalogButtons library:

⦾ Mode 0 to 7: show the basic colors, such as: RED, GREEN, BLUE, WHITE, ORANGE, TEAL, PURPLE, YELLOW.

⦾ Mode 8 (color-wheel mode): The color of each RGB led can be adjusted by holding the pushbutton for longer than 3 seconds.

⦾ Mode 9: Turn off all LED.

Leave a Reply