Arduino
-
전구 불 들어오게 하기Arduino 2022. 7. 15. 12:43
void setup() { pinMode(13, OUTPUT); Serial.begin(9600); } int cnt = 0; boolean check = true; void loop() { int buttonState = digitalRead(11); Serial.println(buttonState); if (buttonState == 1) { if (check == true) { cnt++; check = false; if (cnt == 1) { digitalWrite(13, HIGH); } else if (cnt == 2) { digitalWrite(13, LOW); cnt = 0; } } } else { check = true; } }
-
차단기 만들기Arduino 2022. 7. 15. 12:42
#include Servo myServo; void setup() { digitalWrite(7, INPUT); Serial.begin(9600); pinMode(13, OUTPUT); pinMode(12, OUTPUT); pinMode(11, OUTPUT); pinMode(10, OUTPUT); pinMode(9, OUTPUT); myServo.attach(8); } int cnt = 0; boolean check = true; void loop() { int buttonState = digitalRead(7); Serial.println(buttonState); if(buttonState==1){ if(check==true){ check = false; cnt++; if(cnt==1){..
-
버튼 누를 때마다 led 밝기 정도 다르게 하기Arduino 2022. 7. 15. 12:33
void setup() { pinMode(2, INPUT); pinMode(9, OUTPUT); Serial.begin(9600); } int cnt = 0; boolean check = true; void loop() { int buttonState=digitalRead(2); Serial.println(buttonState); if(buttonState == 1){ if(check == true){ cnt++; check = false; if(cnt== 1){ analogWrite(9, 100); }else if(cnt == 2){ analogWrite(9, 255); }else if(cnt == 3){ analogWrite(9, 0); cnt = 0; } } }else { check =true; } }
-
버튼 한 번 누르면 led 켜고 한 번 누르면 끄기Arduino 2022. 7. 15. 12:00
void setup() { pinMode(2,INPUT); Serial.begin(9600); pinMode(7, OUTPUT); } int cnt =0; boolean check = true; void loop() { int buttonState = digitalRead(2); Serial.println(buttonState); if(buttonState==1){ if(check==true){ cnt++; check = false; if(cnt==1){ digitalWrite(7, HIGH); }else if(cnt == 2) { digitalWrite(7, LOW); cnt=0; } } }else if(buttonState ==0){ check = true; } }
-
피에조 부저를 이용해서 소리내기Arduino 2022. 7. 14. 14:10
void setup() { Serial.begin(9600); } void loop() { int btn1 = digitalRead(6); int btn2 = digitalRead(7); int btn3 = digitalRead(8); int btn4 = digitalRead(9); int btn5 = digitalRead(10); Serial.println(btn5); if(btn1 == 1){ tone(13, 262, 100); }else if(btn2 == 1){ tone(13, 294, 100); }else if(btn3 == 1){ tone(13, 330, 100); }else if(btn4 == 1){ tone(13, 349, 100); }else if(btn5 == 1){ tone(13, 3..