Initial upload
This commit is contained in:
parent
c81e5ebcc5
commit
49486b33bb
82
arc_lamp_control.ino
Normal file
82
arc_lamp_control.ino
Normal file
@ -0,0 +1,82 @@
|
||||
#include <ezButton.h>
|
||||
|
||||
#define ROT_A 12
|
||||
#define ROT_B 11
|
||||
#define LEDS 10
|
||||
ezButton button (6);
|
||||
|
||||
int brightness = 125;
|
||||
int power = 0;
|
||||
int aState;
|
||||
int aLastState;
|
||||
|
||||
void setup() {
|
||||
// Initialize pins
|
||||
pinMode(ROT_A, INPUT_PULLUP);
|
||||
pinMode(ROT_B, INPUT_PULLUP);
|
||||
pinMode(LEDS, OUTPUT);
|
||||
|
||||
// Configure button debounce
|
||||
button.setDebounceTime(50);
|
||||
|
||||
aLastState = digitalRead(ROT_A);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Initialize ezbutton
|
||||
button.loop();
|
||||
|
||||
// ROTARY ENCODER CONTROL //
|
||||
|
||||
// Read state of encoder pin A
|
||||
aState = digitalRead(ROT_A);
|
||||
|
||||
// Check if it's changed
|
||||
if (aState != aLastState && aState == 1){
|
||||
if (digitalRead(ROT_B) != aState){ // If it has...
|
||||
if (brightness < 225 && brightness >= 5){
|
||||
brightness += 5; // Up the brightness
|
||||
}
|
||||
else if (brightness < 5) {
|
||||
brightness++; // If our brightness is low (below duty cycle 5) we only want one step
|
||||
}
|
||||
else if (brightness >= 225 && brightness < 255) {
|
||||
brightness += 10; // As we get brighter we need larger steps
|
||||
}
|
||||
} else {
|
||||
if (brightness > 5 && brightness < 225){
|
||||
brightness -= 5;
|
||||
}
|
||||
else if (brightness <= 5 && brightness > 1) {
|
||||
brightness--;
|
||||
}
|
||||
else if (brightness >= 225) {
|
||||
brightness -= 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
aLastState = aState;
|
||||
|
||||
// BUTTON CONTROL //
|
||||
|
||||
// Check button state
|
||||
if (button.isPressed()){
|
||||
if (power == 0){ // If off, turn on...
|
||||
power = 1;
|
||||
} else { // If on, turn off
|
||||
power = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (button.isReleased()){
|
||||
// DO NOTHING
|
||||
}
|
||||
|
||||
if (power == 1) {
|
||||
analogWrite (LEDS, brightness);
|
||||
} else {
|
||||
analogWrite (LEDS, 0);
|
||||
}
|
||||
delay(1);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user