Skip to content

Instantly share code, notes, and snippets.

@bigjosh
Last active August 29, 2015 14:08
Show Gist options
  • Save bigjosh/358964bad63c53684612 to your computer and use it in GitHub Desktop.
Save bigjosh/358964bad63c53684612 to your computer and use it in GitHub Desktop.
TyTower LED Blink Code
// RGB_Tiny Board Testing for Common Anode Rgb Leds
// with LOW it lgiths up the led and with HIGH it lights off because its INVERTED due to common anode rgb led
/*.
ATTiny85 Pinout
(PCINT5/!RESET//ADC0/dW)PB5 -1 8- VCC
(PCINT3/XTAL1/CLK1/!OC1B/ADC3)PB3 -2 7- PB2(SCK/USCK/SCL/ADC1/T0/INT0/PCINT2)
(PCINT4/XTAL2/CLK0/OC1B/ADC2)PB4 -3 6- PB1(MISO/D0/AIN1/OC0B/OC1A/PCINT1)
GND -4 5- PB0(MOSI/D1/SDA/AIN0/OC0A/!OC1A/AREF/PCINT0)
*/
const int redPin = PB2;
const int greenPin = PB1;
const int bluePin = PB0;
const int delON = 50; // time in ms that LED should blnk on
const int delOFF = 200; // delay in ms between LED blinks in a single cycle
const int delCYCLE = 1000; // delay in ms between cycles
// Setup for outputs
void setup()
{
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
digitalWrite(redPin, HIGH);
digitalWrite(bluePin, HIGH);
digitalWrite(greenPin, HIGH);
}
void loop() {
int sensorValue = analogRead(PB3);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 4.8V):
float voltage = sensorValue * (4.8 / 1023.0);
int value=sensorValue;
if (value<=580) { // Very low voltage- blink red twice...
digitalWrite(redPin, LOW);
delay(delON);
digitalWrite(redPin, HIGH);
delay(delOFF);
digitalWrite(redPin, LOW);
delay(delON);
} else if (value<=600) { // Low voltage - blink red once...
digitalWrite(redPin, LOW);
delay(delON);
} else if (value<=690) { // Good voltage - blink green
digitalWrite(greenPin, LOW);
delay(delON);
} else if (value<=720) { // High voltage - blink blue once
digitalWrite(bluePin, LOW);
delay(delON);
} else { // Very high voltage - blink blue twice
digitalWrite(bluePin, LOW);
delay(delON);
digitalWrite(bluePin, HIGH);
delay(delOFF);
digitalWrite(bluePin, LOW);
delay(delON);
}
// Turn off any LEDs that we turned on this cycle
digitalWrite(bluePin, HIGH);
digitalWrite(redPin, HIGH);
digitalWrite(greenPin, HIGH);
delay( delCYCLE ); // Wait for next cycle
// Note that we could sleep here to save power...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment