Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define potent_pin 0
- int pin_red = 6;
- int pin_green = 10;
- int pin_blue = 3;
- int beeper = 9;
- uint8_t red_bright = 255;
- uint8_t green_bright = 255;
- uint8_t blue_bright = 255;
- uint8_t count = 1;
- uint8_t rgb_state = 1;
- void setup() {
- Serial.begin(9600);
- pinMode(pin_red, OUTPUT);
- pinMode(pin_green, OUTPUT);
- pinMode(pin_blue, OUTPUT);
- pinMode(beeper, OUTPUT);
- pinMode(7, INPUT_PULLUP);
- }
- bool flag = false;
- void loop() {
- btn();
- potent();
- rgb_led();
- Serial.println(rgb_state);
- if (flag == true) {
- analogWrite(beeper, 250);
- }
- else{
- analogWrite(beeper, 0);
- }
- delay(5);
- }
- void btn(){
- bool btnState = !digitalRead(7);
- if (btnState && !flag) {
- flag = true;
- rgb_state++;
- if (rgb_state > 3){
- rgb_state = 1;
- }
- }
- if (!btnState && flag){
- flag = false;
- }
- }
- void potent(){
- count = map(analogRead(potent_pin),0,1023,0,255);
- switch(rgb_state) {
- case 1:
- red_bright = count;
- case 2:
- green_bright = count;
- case 3:
- blue_bright = count;
- }
- }
- void rgb_led(){
- analogWrite(pin_red, red_bright);
- analogWrite(pin_green, green_bright);
- analogWrite(pin_blue, blue_bright);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement