#include <MyButton.h>
#include <MyLed.h>
MyButton myBtn(2);
MyLed myLed1(8);
MyLed myLed2(9);
void setup() {
Serial.begin(9600);
}
void loop() {
myLed2.ledblink();
myBtn.isPressed();
if (myBtn.isPressed() == true){
Serial.println("btn not pressed");
myLed1.ledoff();
}
else{
Serial.println("btn pressed");
myLed1.ledon();
}
}
#include <MyButton.h>
#include <MyLed.h>
MyButton myBtn(2);
MyLed myLed1(8);
MyLed myLed2(9);
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 8; // the number of the LED pin
// Variables will change:
int ledState = HIGH; // the current state of the output pin
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
void setup() {
Serial.begin(9600);
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
myLed1.ledoff();
}
void loop() {
int reading = digitalRead(2);
if (reading != lastButtonState) {
lastDebounceTime = millis();
}
if ((millis() - lastDebounceTime) > debounceDelay) {
if (reading != buttonState) {
buttonState = reading;
if (buttonState == HIGH) {
ledState = !ledState;
Serial.println("button pressed. LED ON");
myLed1.ledon();
}
else{
myLed1.ledoff();
}
}
}
lastButtonState = reading;
myBtn.isPressed();
}
'C++ > c++수업' 카테고리의 다른 글
class - btn+led 버튼 누르면 led on off (0) | 2020.10.27 |
---|---|
아두이노 라이브러리 (led 깜빡이는) 만들기 (0) | 2020.10.26 |
고객 차량 관리 프로그램을 위한 클래스 설계. (2개의 클래스가 사용 (0) | 2020.10.21 |
학생관리 프로그램을 위한 학생(Student) 클래스 설계 (0) | 2020.10.20 |
배열 포인터 (0) | 2020.10.20 |