added KiCAD Files and MANUAL.md
This commit is contained in:
parent
d0d1353a8a
commit
6457210857
84 changed files with 382083 additions and 19 deletions
20
firmware/README.md
Normal file
20
firmware/README.md
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# Pocket Psithemius
|
||||
|
||||
Firmware for the Pocket Psithemius device.
|
||||
|
||||
## Installation
|
||||
|
||||
* Set up an Arduino as ISP programmer following [this tutorial](https://www.arduino.cc/en/Tutorial/ArduinoISP) or use any other ICSP compatible programmer.
|
||||
* The firmware depends on the [OneButton library](https://github.com/mathertel/OneButton) which you need to install with the IDE's Library Manager
|
||||
* Connect the Pocket Psithemius via ICSP to the programmer.
|
||||
|
||||
### IDE Tools Settings
|
||||
|
||||
* Board: Attiny24/44/84
|
||||
* Chip: Attiny84
|
||||
* Clock: 8MHz (internal)
|
||||
* B.O.D. Level: B.O.D. Disabled
|
||||
* Save EEPROM: EEPROM retained
|
||||
* Pin Mapping: clockwise
|
||||
* LTO: Enabled
|
||||
* millis()/micros(): Enabled
|
||||
363
firmware/pocketpsithemius .ino.bak
Normal file
363
firmware/pocketpsithemius .ino.bak
Normal file
|
|
@ -0,0 +1,363 @@
|
|||
/*Copyright (c) 2020 Sublunar Psionics
|
||||
|
||||
Special Thanks to Slavko Andrejevic for providing the main framework of this
|
||||
firmware and for technical support.
|
||||
|
||||
---- MIT License ----
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#define Attiny 84 //84 or 261
|
||||
|
||||
#if Attiny == 261
|
||||
#define btnA 9 //PB0 / Button A:
|
||||
#define btnB 8 //PB1 / Button B:
|
||||
#define btnC 13 //PA7 / Button C:
|
||||
#define led_R 12 //PA6 / RED LED
|
||||
#define led_G 14 //PA3 / GREEN LED
|
||||
#define led_B 1 //PA1 / BLUE LED
|
||||
#define uv_LED 6 //PB3 / UV LED
|
||||
#define OPAMP 3 //PB6 / turns on the Op Amp circuit
|
||||
#endif
|
||||
|
||||
#if Attiny == 84
|
||||
#define btnA A0 //PA0 / Button A:
|
||||
#define btnB A1 //PA1 / Button B:
|
||||
#define btnC A2 //PA2 / Button C:
|
||||
#define led_R A4 //PA4 / RED LED
|
||||
#define led_G A5 //PA5 / GREEN LED
|
||||
#define led_B A6 //PA6 / BLUE LED
|
||||
#define uv_LED A3 //PA3 / UV LED
|
||||
#define OPAMP 8 //PB2 / turns on the Op Amp circuit
|
||||
#define ANALOG A7 //PB2 / Get analog
|
||||
#endif
|
||||
|
||||
#define ON HIGH
|
||||
#define OFF LOW
|
||||
|
||||
//---- BUTTONS ----
|
||||
byte counterA = 0; //count push btnA:
|
||||
byte counterB = 0; //count push btnB:
|
||||
byte counterC = 0; //count push btnC:
|
||||
bool enabled_btnAC = true; //Button A + C enabled or not
|
||||
bool enabled_btnB = true; //Button B enabled or not
|
||||
static bool last_btnA = false; //Previous state of button A
|
||||
static bool last_btnB = false; //Previous state of button B
|
||||
static bool last_btnC = false; //Previous state of button C
|
||||
|
||||
//---- LEDS ----
|
||||
bool enabled_LED = false; //turn on a tricolor LED
|
||||
bool was_on_LED = false; //was LED on?
|
||||
bool usePWM = false; //use softPWM for more nuanced colors
|
||||
bool dimmer = false; //LED brightness follows analog input signal
|
||||
void offLeds() {
|
||||
analogWrite(led_R, 255);
|
||||
analogWrite(led_B, 255);
|
||||
analogWrite(led_G, 255);
|
||||
}
|
||||
|
||||
//---- TIMER ----
|
||||
bool countDelay = false; //are we counting ticks to time out the UV LEDs?
|
||||
static uint32_t delayCount = 0;
|
||||
#if Attiny == 84
|
||||
uint32_t oldTime = millis();
|
||||
#endif
|
||||
long lastDebounceTime = 0; // the last time the output pin was toggled
|
||||
long debounceDelay = 50; // the debounce time; increase if the output flickers
|
||||
|
||||
//---- COLOR ----
|
||||
struct COLOR { //Creating structure for colors
|
||||
byte r;
|
||||
byte g;
|
||||
byte b;
|
||||
};
|
||||
COLOR selectedColor = { 0 , 0 , 0 };
|
||||
|
||||
void setColor(COLOR paint, bool full = true) {
|
||||
//tricolor LED color
|
||||
selectedColor = paint;
|
||||
selectedColor.r = 255 - paint.r;
|
||||
selectedColor.b = 255 - paint.b;
|
||||
selectedColor.g = 255 - paint.g;
|
||||
//paint contains r g b value for pwm on pins
|
||||
showColor();
|
||||
}
|
||||
|
||||
void showColor() { // 100% of color
|
||||
if (enabled_LED == true) {
|
||||
#if Attiny == 84
|
||||
byte full = 100;
|
||||
if( dimmer == true ){
|
||||
full = (255 / analogRead(ANALOG)) * full;
|
||||
}
|
||||
softPWM(led_R, selectedColor.r - ((selectedColor.r / full) * full), 1);
|
||||
softPWM(led_B, selectedColor.b - ((selectedColor.b / full) * full) , 1);
|
||||
softPWM(led_G, selectedColor.g - ((selectedColor.g / full) * full) , 1);
|
||||
#else
|
||||
softPWM(led_R, selectedColor.r, 1);
|
||||
softPWM(led_B, selectedColor.b, 1);
|
||||
softPWM(led_G, selectedColor.g, 1);
|
||||
#endif
|
||||
} else {
|
||||
offLeds();
|
||||
}
|
||||
}
|
||||
|
||||
//---- PLANETARY COLORS ----
|
||||
COLOR white = { 255 , 255 , 255 }; //Moon correspondence
|
||||
COLOR orange = { 255 , 128 , 0 }; //Mercury correspondence
|
||||
COLOR green = { 0 , 255 , 0 }; //Venus correspondence
|
||||
COLOR yellow = { 255 , 255 , 0 }; //Sol correspondence
|
||||
COLOR red = { 255 , 0 , 0 }; //Mars correspondence
|
||||
COLOR blue = { 0 , 128 , 255 }; //Jupiter correspondence
|
||||
COLOR purple = { 128 , 0 , 128 }; //Jupiter/Moon correspondence
|
||||
COLOR indigo = { 111 , 0 , 255 }; //Saturn correspondence
|
||||
COLOR grey = { 40 , 40 , 40 }; //Saturn correspondence
|
||||
|
||||
//---- DEVICE SETUP ----
|
||||
void setup() {
|
||||
|
||||
//Buttons
|
||||
pinMode(btnA, INPUT);
|
||||
pinMode(btnB, INPUT);
|
||||
pinMode(btnC, INPUT);
|
||||
|
||||
//LEDS
|
||||
pinMode(led_B, OUTPUT);
|
||||
pinMode(led_G, OUTPUT);
|
||||
pinMode(led_R, OUTPUT);
|
||||
offLeds();
|
||||
|
||||
//UV LED
|
||||
pinMode(uv_LED, OUTPUT);
|
||||
digitalWrite(uv_LED, OFF);
|
||||
|
||||
// OP AMP
|
||||
#if Attiny == 84
|
||||
pinMode(ANALOG, INPUT);
|
||||
#endif
|
||||
pinMode(OPAMP, OUTPUT);
|
||||
digitalWrite(OPAMP, OFF);
|
||||
}
|
||||
|
||||
//---- DEVICE LOOP ----
|
||||
void loop() {
|
||||
|
||||
// Detect and debounce button presses
|
||||
if ( (millis() - lastDebounceTime) > debounceDelay) {
|
||||
|
||||
//Button A:
|
||||
bool pressed_btnA = !digitalRead(btnA);
|
||||
if (pressed_btnA != last_btnA ) {
|
||||
if (pressed_btnA == true) {
|
||||
counterA++;
|
||||
if (counterA > 10)counterA = 1;
|
||||
pressButton_A();
|
||||
}
|
||||
last_btnA = pressed_btnA;
|
||||
}
|
||||
|
||||
//Button B:
|
||||
bool pressed_btnB = !digitalRead(btnB);
|
||||
if (pressed_btnB != last_btnB ) {
|
||||
if (pressed_btnB == true) {
|
||||
counterB++;
|
||||
if (counterB > 2)counterB = 1;
|
||||
pressButton_B();
|
||||
}
|
||||
last_btnB = pressed_btnB;
|
||||
}
|
||||
|
||||
//Button C:
|
||||
bool pressed_btnC = !digitalRead(btnC);
|
||||
if (pressed_btnC != last_btnC ) {
|
||||
if (pressed_btnC == true) {
|
||||
counterC++;
|
||||
#if Attiny == 84
|
||||
if (counterC > 4)counterC = 1;
|
||||
#else
|
||||
if (counterC > 2)counterC = 1;
|
||||
#endif
|
||||
pressButton_C();
|
||||
}
|
||||
last_btnC = pressed_btnC;
|
||||
}
|
||||
lastDebounceTime = millis(); //set the current time
|
||||
}
|
||||
|
||||
showColor();
|
||||
|
||||
//Counts up and turns UV LED off after 1min
|
||||
#if Attiny == 261
|
||||
if (countDelay == true) {
|
||||
delayCount++;
|
||||
counterB = 1;
|
||||
}
|
||||
else delayCount = 0;
|
||||
if (delayCount > 1200000) {
|
||||
#endif
|
||||
#if Attiny == 84
|
||||
if ( countDelay == true && ((millis()-oldTime) > 60000)) {
|
||||
#endif
|
||||
//Turn the UV LED off
|
||||
digitalWrite(uv_LED, LOW);
|
||||
countDelay = false;
|
||||
//Reenable all buttons
|
||||
enabled_btnAC = true;
|
||||
//LED Status back to before Button B was pushed
|
||||
enabled_LED = was_on_LED;
|
||||
}
|
||||
}
|
||||
|
||||
//---- BUTTON STATE MACHINE FUNCTIONS
|
||||
//Button A:
|
||||
void pressButton_A() {
|
||||
if (enabled_btnAC == false) {
|
||||
counterA = 0;
|
||||
return;//Chek if button is disabled
|
||||
}
|
||||
switch (counterA) {
|
||||
case 1:
|
||||
enabled_LED = true;
|
||||
setColor(white, true);
|
||||
break;
|
||||
case 2:
|
||||
usePWM = true;
|
||||
setColor(orange, true);
|
||||
break;
|
||||
case 3:
|
||||
usePWM = false;
|
||||
setColor(green, true);
|
||||
break;
|
||||
case 4:
|
||||
setColor(yellow, true);
|
||||
break;
|
||||
case 5:
|
||||
setColor(red, true);
|
||||
break;
|
||||
case 6:
|
||||
setColor(blue, true);
|
||||
break;
|
||||
case 7:
|
||||
usePWM = true;
|
||||
setColor(purple, true);
|
||||
break;
|
||||
case 8:
|
||||
setColor(indigo, true);
|
||||
break;
|
||||
case 9:
|
||||
setColor(grey, true);
|
||||
break;
|
||||
case 10:
|
||||
enabled_LED = false;
|
||||
counterA = 0;//TURN OFF
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Button B:
|
||||
void pressButton_B() {
|
||||
if (enabled_btnB == false) {
|
||||
counterB = 0;
|
||||
return;
|
||||
}
|
||||
if (counterB == 1) { //1st press:
|
||||
//was color LED on when button was pushed?
|
||||
was_on_LED = enabled_LED;
|
||||
//Disable LED and buttons A and C
|
||||
enabled_LED = false;
|
||||
counterA = 0;
|
||||
counterC = 0;
|
||||
enabled_btnAC = false;
|
||||
enabled_btnB == false;
|
||||
//Turn off Op-Amp circuit
|
||||
digitalWrite(OPAMP, OFF);
|
||||
enabled_btnB == true;
|
||||
digitalWrite(uv_LED, ON);
|
||||
#if Attiny == 84
|
||||
if ( countDelay == false ) {
|
||||
oldTime = millis();
|
||||
}
|
||||
#endif
|
||||
countDelay = true; // turn on delay counter in loop()
|
||||
}
|
||||
if (counterB == 2) { //2nd press:
|
||||
if (digitalRead(uv_LED) == ON) {
|
||||
//Turn UV LED off
|
||||
digitalWrite(uv_LED, OFF);
|
||||
}
|
||||
//Re-enable all buttons
|
||||
enabled_btnAC = true;
|
||||
enabled_btnB = true;
|
||||
//LED Status back to before Button B was pushed
|
||||
enabled_LED = was_on_LED;
|
||||
//reset delay counter
|
||||
countDelay = false;
|
||||
}
|
||||
}
|
||||
|
||||
//Button C:
|
||||
void pressButton_C() {
|
||||
if (enabled_btnAC == false) {
|
||||
counterC = 0;
|
||||
return;
|
||||
}
|
||||
#if Attiny == 84
|
||||
if (counterC == 1) { //1st press:
|
||||
dimmer = true;
|
||||
}
|
||||
if (counterC == 2) { //2nd press:
|
||||
dimmer = false;
|
||||
digitalWrite(OPAMP, ON);
|
||||
}
|
||||
if (counterC == 3) { //3rd press:
|
||||
dimmer = true;
|
||||
digitalWrite(OPAMP, ON);
|
||||
}
|
||||
if (counterC == 4) { //2nd press:
|
||||
digitalWrite(OPAMP, OFF);
|
||||
}
|
||||
#else
|
||||
if (counterC == 1) { //1st press:
|
||||
digitalWrite(OPAMP, ON);
|
||||
}
|
||||
if (counterC == 2) { //2nd press:
|
||||
digitalWrite(OPAMP, OFF);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
//---- SOFTWARE PWM ----
|
||||
// software PWM function that fakes analog output
|
||||
void softPWM(byte pin, byte freq, byte sp) {
|
||||
byte delay1 = 255 - freq;
|
||||
if (usePWM == true) {
|
||||
while (sp > 0) {
|
||||
digitalWrite(pin, LOW); //on
|
||||
delayMicroseconds(freq);
|
||||
digitalWrite(pin, HIGH); //off
|
||||
delayMicroseconds(delay1);
|
||||
sp--;
|
||||
}
|
||||
} else {
|
||||
analogWrite(pin, 255 - freq);
|
||||
}
|
||||
}
|
||||
327
firmware/pocketpsithemius.ino
Normal file
327
firmware/pocketpsithemius.ino
Normal file
|
|
@ -0,0 +1,327 @@
|
|||
/*Copyright (c) 2020 Sublunar Psionics
|
||||
|
||||
Special Thanks to Slavko Andrejevic for providing the main framework of this
|
||||
firmware and for technical support.
|
||||
|
||||
---- MIT License ----
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
*/
|
||||
|
||||
#include <OneButton.h>
|
||||
|
||||
#define btnA 0 // PA0 / Button A:
|
||||
#define btnB 2 // PA1 / Button B:
|
||||
#define btnC 1 // PA2 / Button C:
|
||||
#define led_R 4 // PA4 / RED LED
|
||||
#define led_G 5 // PA5 / GREEN LED
|
||||
#define led_B 6 // PA6 / BLUE LED
|
||||
#define uv_LED 3 // PA3 / UV LED
|
||||
#define OPAMP 8 // PB2 / turns on the Op Amp circuit
|
||||
#define ANALOG 7 // PA7 / Get analog
|
||||
#define REG1 9 // PB1 / unconnected
|
||||
#define REG2 10 // PB0 / unconnected
|
||||
|
||||
#define ON HIGH
|
||||
#define OFF LOW
|
||||
|
||||
//---- BUTTONS ----
|
||||
|
||||
byte counterA = 0; // count push btnA:
|
||||
byte counterB = 0; // count push btnB:
|
||||
byte counterC = 0; // count push btnC:
|
||||
bool enabled_btnAC = true; // Button A + C enabled or not
|
||||
bool enabled_btnB = true; // Button B enabled or not
|
||||
|
||||
OneButton buttonA(btnA, true); // Button A setup
|
||||
OneButton buttonB(btnB, true); // Button B setup
|
||||
OneButton buttonC(btnC, true); // Button C setup
|
||||
|
||||
//---- LEDS ----
|
||||
|
||||
bool enabled_LED = false; //turn on a tricolor LED
|
||||
bool usePWM = false; //use softPWM for more nuanced colors
|
||||
bool disco = false; // random colors
|
||||
|
||||
//---- TIMER ----
|
||||
|
||||
bool countDelay = false; //are we counting ticks to time out the UV LEDs?
|
||||
uint32_t oldTime = millis();
|
||||
|
||||
//---- COLOR ----
|
||||
|
||||
struct COLOR { // Creating structure for colors
|
||||
byte r;
|
||||
byte g;
|
||||
byte b;
|
||||
};
|
||||
COLOR selectedColor = { 0, 0, 0 };
|
||||
|
||||
//---- PLANETARY COLORS ----
|
||||
|
||||
COLOR white = { 255 , 255 , 255 }; // Moon correspondence
|
||||
COLOR orange = { 255 , 128 , 0 }; // Mercury correspondence
|
||||
COLOR green = { 0 , 255 , 0 }; // Venus correspondence
|
||||
COLOR yellow = { 255 , 255 , 0 }; // Sol correspondence
|
||||
COLOR red = { 255 , 0 , 0 }; // Mars correspondence
|
||||
COLOR blue = { 0 , 128 , 255 }; // Jupiter correspondence
|
||||
COLOR purple = { 128 , 0 , 128 }; // Jupiter/Moon correspondence
|
||||
COLOR indigo = { 111 , 0 , 255 }; // Saturn correspondence
|
||||
COLOR grey = { 40 , 40 , 40 }; // Saturn correspondence
|
||||
|
||||
//---- DEVICE SETUP ----
|
||||
void setup() {
|
||||
|
||||
// BUTTONS
|
||||
buttonA.attachClick(cycleColors);
|
||||
buttonA.attachLongPressStart(discoStart);
|
||||
buttonB.attachClick(ultraviolet);
|
||||
buttonB.attachLongPressStart(uvForever);
|
||||
buttonC.attachClick(opAmp);
|
||||
|
||||
// LEDS
|
||||
pinMode(led_B, OUTPUT);
|
||||
pinMode(led_G, OUTPUT);
|
||||
pinMode(led_R, OUTPUT);
|
||||
offLeds();
|
||||
|
||||
// UV LED
|
||||
pinMode(uv_LED, OUTPUT);
|
||||
digitalWrite(uv_LED, OFF);
|
||||
|
||||
// OP AMP
|
||||
//pinMode(ANALOG, INPUT);
|
||||
pinMode(OPAMP, OUTPUT);
|
||||
digitalWrite(OPAMP, OFF);
|
||||
|
||||
}
|
||||
|
||||
//---- DEVICE LOOP ----
|
||||
void loop() {
|
||||
|
||||
buttonA.tick();
|
||||
buttonB.tick();
|
||||
buttonC.tick();
|
||||
showColor();
|
||||
|
||||
// If enabled, turns UV LED off after 1min
|
||||
if ( countDelay == true && ((millis()-oldTime) > 60000)) {
|
||||
//Turn the UV LED off
|
||||
enabled_btnAC = true;
|
||||
digitalWrite(uv_LED, OFF);
|
||||
counterB = 0;
|
||||
countDelay = false;
|
||||
}
|
||||
|
||||
if ( disco == true ) {
|
||||
enabled_LED = true;
|
||||
usePWM = false;
|
||||
selectedColor.r = rng();
|
||||
selectedColor.g = rng();
|
||||
selectedColor.b = rng();
|
||||
//digitalWrite(uv_LED, bitRead(rng(), 0));
|
||||
showColor();
|
||||
delay(rng());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//---- FUNCTIONS ----
|
||||
|
||||
// turn all LEDs off
|
||||
void offLeds() {
|
||||
analogWrite(led_R, 255);
|
||||
analogWrite(led_B, 255);
|
||||
analogWrite(led_G, 255);
|
||||
}
|
||||
|
||||
// set a color
|
||||
void setColor(COLOR paint, bool full = true) {
|
||||
//tricolor LED color
|
||||
selectedColor.r = paint.r;
|
||||
selectedColor.b = paint.b;
|
||||
selectedColor.g = paint.g;
|
||||
showColor();
|
||||
}
|
||||
|
||||
// show the color or turn off
|
||||
void showColor() { // 100% of color
|
||||
if (enabled_LED == true) {
|
||||
softPWM(led_R, selectedColor.r, 1);
|
||||
softPWM(led_B, selectedColor.b, 1);
|
||||
softPWM(led_G, selectedColor.g, 1);
|
||||
} else {
|
||||
offLeds();
|
||||
}
|
||||
}
|
||||
|
||||
void discoStart() {
|
||||
if ( disco == true ) {
|
||||
disco = false;
|
||||
enabled_LED = false;
|
||||
//digitalWrite(uv_LED, OFF);
|
||||
counterA = 0;
|
||||
}
|
||||
else disco = true;
|
||||
}
|
||||
|
||||
// used for button A to cycle through the colors
|
||||
void cycleColors() {
|
||||
if ( disco == true) discoStart();
|
||||
if (enabled_btnAC == true) {
|
||||
counterA++;
|
||||
switch (counterA) {
|
||||
case 1:
|
||||
enabled_LED = true;
|
||||
setColor(white, true);
|
||||
break;
|
||||
case 2:
|
||||
usePWM = true;
|
||||
setColor(orange, true);
|
||||
break;
|
||||
case 3:
|
||||
usePWM = false;
|
||||
setColor(green, true);
|
||||
break;
|
||||
case 4:
|
||||
setColor(yellow, true);
|
||||
break;
|
||||
case 5:
|
||||
setColor(red, true);
|
||||
break;
|
||||
case 6:
|
||||
setColor(blue, true);
|
||||
break;
|
||||
case 7:
|
||||
usePWM = true;
|
||||
setColor(purple, true);
|
||||
break;
|
||||
case 8:
|
||||
setColor(indigo, true);
|
||||
break;
|
||||
case 9:
|
||||
setColor(grey, true);
|
||||
break;
|
||||
case 10:
|
||||
enabled_LED = false;
|
||||
counterA = 0;//TURN OFF
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// used for button B to toggle the UV LEDs
|
||||
void ultraviolet() {
|
||||
counterA = 0;
|
||||
if ( disco == true) discoStart();
|
||||
if (enabled_btnB == true) {
|
||||
counterB++;
|
||||
switch (counterB) {
|
||||
case 1:
|
||||
blinker(led_B, 500, 5);
|
||||
enabled_LED = false;
|
||||
enabled_btnAC = false;
|
||||
digitalWrite(uv_LED, ON);
|
||||
if ( countDelay == false ) {
|
||||
oldTime = millis();
|
||||
}
|
||||
countDelay = true; // turn on delay counter in loop()
|
||||
break;
|
||||
case 2:
|
||||
enabled_btnAC = true;
|
||||
digitalWrite(uv_LED, OFF);
|
||||
counterB = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// disable all buttons and keep UV light running forever
|
||||
void uvForever() {
|
||||
blinker(led_B, 500, 5);
|
||||
blinker(led_B, 50, 10);
|
||||
enabled_btnB = false;
|
||||
enabled_btnAC = false;
|
||||
countDelay = false;
|
||||
digitalWrite(uv_LED, ON);
|
||||
}
|
||||
|
||||
// used for button C to toggle the OP Amp
|
||||
void opAmp() {
|
||||
if (enabled_btnAC == true) {
|
||||
counterC++;
|
||||
switch (counterC) {
|
||||
case 1:
|
||||
blinker(led_G, 50, 2);
|
||||
digitalWrite(OPAMP, ON);
|
||||
break;
|
||||
case 2:
|
||||
blinker(led_R, 50, 2);
|
||||
digitalWrite(OPAMP, OFF);
|
||||
counterC = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// helper to blink a color
|
||||
void blinker(byte pin, int len, byte rep) {
|
||||
byte counter = 1;
|
||||
while (counter <= rep) {
|
||||
analogWrite(pin, 0);
|
||||
delay(len);
|
||||
offLeds();
|
||||
delay(len);
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
// software PWM function that fakes analog output
|
||||
void softPWM(byte pin, byte freq, byte sp) {
|
||||
byte delay1 = 255 - freq;
|
||||
if (usePWM == true) {
|
||||
while (sp > 0) {
|
||||
digitalWrite(pin, LOW); //on
|
||||
delayMicroseconds(freq);
|
||||
digitalWrite(pin, HIGH); //off
|
||||
delayMicroseconds(delay1);
|
||||
sp--;
|
||||
}
|
||||
} else {
|
||||
analogWrite(pin, 255 - freq);
|
||||
}
|
||||
}
|
||||
|
||||
byte rng() {
|
||||
int raw0, raw1;
|
||||
byte b0, b1, x, col, twoBytes[2], result;
|
||||
col = 0;
|
||||
while ( col <= 1 ) {
|
||||
raw0 = analogRead(REG1);
|
||||
raw1 = analogRead(REG2);
|
||||
b0 = lowByte(raw0);
|
||||
b1 = lowByte(raw1);
|
||||
x = b0 ^ b1;
|
||||
twoBytes[col] = x;
|
||||
col++;
|
||||
}
|
||||
result = (twoBytes[0]<<4)+twoBytes[1];
|
||||
return result;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue