PLAYSTATION PICO I

LOCAL MULTIPLAYER CONSOLE. TWO BUTTONS ONE LED.

Hier steht der Quelltext

A simple button helper class to manage button input in parallel.

// --------------
// TRXY'S Digital Button helper class called btn.h
// -------------
class aBUTT {
  private:
    byte bpin;
    long ts = 0;
    bool previous_state = false;
    bool previous_state_holded = false;
 
  public:
    bool is_pressed = false;
    bool is_holded = false;
 
    bool on_pressed = false;
    bool on_released = false;
    bool on_holded = false;
 
    aBUTT(byte bpin) {
      this->bpin = bpin;
      init();
    }
    void init() {
      pinMode(bpin, INPUT);
 
 
    }
 
 
    void operateBUTTON() {
 
      is_pressed = digitalRead(bpin);
 
 
      on_pressed = false;
      on_released = false;
 
      if (previous_state != is_pressed) {
 
        if (is_pressed) {
 
          ts = millis();
          on_pressed = true;
 
        } else {
 
          on_released = true;
          is_holded = false;
          on_holded = false;
          previous_state_holded = on_holded;
        }
 
        previous_state = is_pressed;
 
      }
 
      on_holded = false;
      if (ts + 1000 < millis() && is_pressed ) {
 
        is_holded = true;
 
 
        if (previous_state_holded != is_holded && is_pressed ) {
 
          on_holded = true;
          previous_state_holded = is_holded;
          //Serial.println("holdi");
        }
      }
    }
};

Main script to manage LED and Buttons

#include <Arduino.h>
#include <trxy_btn_helpers.h>
#include <trxy_led_helpers.h>

aBUTT button1(12);
aLED led1(13);

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  //pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
}

// the loop function runs over and over again forever
void loop() {

  led1.operateLED(); //operate specific LED
  button1.operateBUTTON(); // operate specific button

     if(button1.is_pressed){
 
        led1.setMode(1);
        led1.pulse_speed = .01;
      }else{
 
        led1.setMode(0);
        led1.brightness = 0;
      }

    
  delay(10); 
  
}