Commit b2f27348 authored by Philip Hozier's avatar Philip Hozier
Browse files

week12 program update

parent 226c163e
Pipeline #227493 passed with stages
in 20 seconds
......@@ -324,4 +324,5 @@ As for my final project this RGB output will suffice, and now i have some experi
| [Interior](../week12/wk12-RGB-LED-TRACES.png "Interior") | The interior for milling. |
| [ATtiny1614 datasheet](../week12/ATtiny1614-16-17-DataSheet-DS40002204A.pdf "ATtiny1614 datasheet") | ATtiny1614 datasheet. |
| [ATtiny1614 datasheet](../week12/CLV1A-FKB_RGB-LED-datasheet.pdf "CLV1A-FKB RGB LED datasheet") | CLV1A-FKB RGB LED datasheet. |
| [KiCad](../week12/KiCad-RGB-LED.zip "KiCad files") | KiCad files |
\ No newline at end of file
| [KiCad](../week12/KiCad-RGB-LED.zip "KiCad files") | KiCad files |
| [Arduino Program](../week12/BASIC-LED.ino "Arduino program") | Basic program to test LEDs|
\ No newline at end of file
///////// SEPERATE LED
#define LED_RED A5
#define LED_ORANGE A6
#define LED_GREEN A7
////////////// RGB LED
#define LED_Rgb A1
#define LED_rGb A2
#define LED_rgB A3
// RGB ARRAYS
int RGB_Array[] = {LED_Rgb, LED_rGb, LED_rgB};
int RGB_ArrayCount = sizeof(RGB_Array) / sizeof(RGB_Array[0]);
// Rainbow variables
float Rgb_duty = 0.9;
float rGb_duty = 0.1;
float rgB_duty = 0.4;
float Rgb_LED_off = 1 - Rgb_duty;
float rGb_LED_off = 1 - rGb_duty;
float rgB_LED_off = 1 - rgB_duty;
float RgbValue = -0.1, rGbValue = 0.1, rgBValue = -0.1;
// Rainbow ARRAYS
float RGB_Rainbow_Array[] = {Rgb_duty, rGb_duty, rgB_duty};
int RGB_Rainbow_ArrayCount = sizeof(RGB_Rainbow_Array) / sizeof(RGB_Rainbow_Array[0]);
float RGBValue_Array[] = {RgbValue, rGbValue, rgBValue};
int RGBValue_ArrayCount = sizeof(RGBValue_Array) / sizeof(RGBValue_Array[0]);
float RGBoffValue_Array[] = {Rgb_LED_off, rGb_LED_off, rgB_LED_off};
///////////// PWM variables
int LED_cycle = 1000 / 100; // length of LED cycle
float LED_duty = 0.9; // Brightness of LED
float LED_off = 1 - LED_duty; //
// OTHER variables
int myDelay = 1000;
int MODUS = 0;
float PWM_interval = 0.01;
////////////////// INPUT
#define BUTTON_pin A4
void setup() {
// SEPERATE LED
pinMode(LED_RED, OUTPUT);// Must be HIGH to be on!
pinMode(LED_ORANGE, OUTPUT);//
pinMode(LED_GREEN, OUTPUT);//
// RGB LED
pinMode(LED_Rgb, OUTPUT);// must be LOW to be on!
pinMode(LED_rGb, OUTPUT);//
pinMode(LED_rgB, OUTPUT);//
// Set to HIGH (off)
digitalWrite(LED_Rgb, HIGH);
digitalWrite(LED_rGb, HIGH);
digitalWrite(LED_rgB, HIGH);
// INPUT
pinMode(BUTTON_pin, INPUT_PULLUP);
}
void loop() {
if (digitalRead(BUTTON_pin) == LOW) {
MODUS++;
ChangeMode();
}
// add delay
delay(50);
}
void ChangeMode() {
// Modes
switch (MODUS) {
case 0:
// OFF
break;
case 1:
TrafficLights();
break;
case 2:
Glow();
break;
case 3:
Rainbow();
break;
default:
// reset MODUS
MODUS = 0;
break;
}
}
///////////////// LIGHT FUNCTIONS
/// RGB OFF
void RGB_off() {
for (int k = 0; k <= RGB_ArrayCount - 1; k++) {
digitalWrite(RGB_Array[k], HIGH);
}
}
// Blink
void Blink (int whichPin, float myLED_duty, float myLED_off) {
digitalWrite(whichPin, LOW); // LOW is on.
delay(LED_cycle * myLED_duty);
digitalWrite(whichPin, HIGH);
delay(LED_cycle * myLED_off);
}
// BlinkThree
void BlinkThree () {
int mySpeed = RGB_ArrayCount * 8;
int myLED_cycle = LED_cycle;
// slow down by repeating
for (int n = 0; n <= mySpeed; n++) {
for (int k = 0; k <= RGB_ArrayCount - 1; k++) {
digitalWrite(RGB_Array[k], LOW); // LOW is on.
delay(myLED_cycle * RGB_Rainbow_Array[k]);
digitalWrite(RGB_Array[k], HIGH);
delay(myLED_cycle * (1 - RGB_Rainbow_Array[k]));
}
}
}
/// TRAFFIC LIGHTS SEQUENCE
void TrafficLights() {
digitalWrite(LED_RED, HIGH);
delay(myDelay);
digitalWrite(LED_ORANGE, HIGH);
delay(myDelay);
digitalWrite(LED_RED, LOW);
digitalWrite(LED_ORANGE, LOW);
digitalWrite(LED_GREEN, HIGH);
delay(myDelay);
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_ORANGE, HIGH);
delay(myDelay);
digitalWrite(LED_ORANGE, LOW);
digitalWrite(LED_RED, HIGH);
delay(myDelay);
digitalWrite(LED_RED, LOW);
}
/// GLOW SEQUENCE
void Glow() {
for (int k = 0; k <= RGB_ArrayCount - 1; k++) {
// ramp up
for (float i = 0; i <= 1; i = i + PWM_interval) {
LED_duty = i;
LED_off = 1 - LED_duty;
// Blink
Blink(RGB_Array[k], LED_duty, LED_off);
}
// ramp down
for (float j = 1; j >= 0; j = j - PWM_interval) {
LED_duty = j;
LED_off = 1 - LED_duty;
// Blink
Blink(RGB_Array[k], LED_duty, LED_off);
}
}// END k
// GLOW WHITE
for (float i = 0; i <= 1; i = i + PWM_interval) {
for (int k = 0; k <= RGB_ArrayCount - 1; k++) {
LED_duty = i;
LED_off = 1 - LED_duty;
// Blink
Blink(RGB_Array[k], LED_duty, LED_off);
}
}
// ramp down
for (float j = 1; j >= 0; j = j - PWM_interval) {
for (int k = 0; k <= RGB_ArrayCount - 1; k++) {
LED_duty = j;
LED_off = 1 - LED_duty;
// Blink
Blink(RGB_Array[k], LED_duty, LED_off);
}
}
}// END Glow
/// RAINBOW SEQUENCE
void Rainbow() {
int myDuration = 50;
// ramp up
for (int i = 0; i <= myDuration; i++) {
BlinkThree();
// update values
for (int m = 0; m <= RGB_Rainbow_ArrayCount - 1; m++) {
RGB_Rainbow_Array[m] = RGB_Rainbow_Array[m] + RGBValue_Array[m];
}
// change direction
for (int j = 0; j <= RGB_Rainbow_ArrayCount - 1; j++) {
if (RGB_Rainbow_Array[j] >= 1 || RGB_Rainbow_Array[j] <= 0) {
RGBValue_Array[j] = RGBValue_Array[j] * -1;
}
}
}
}// END Rainbow
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment