Day4 05-DCmotor, button 2
2024. 2. 4. 15:53ㆍarduino
- DC 모터와 버튼을 이용한 간이 선풍기 만들기
#include <Debouncer.h>
// 선풍기
const int MA_IA = 10;
const int MA_IB = 9;
const int btnPin = 2;
int DCSpeed = 0;
Debouncer myDebouncer(btnPin);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(MA_IA, OUTPUT);
pinMode(MA_IB, OUTPUT);
pinMode(btnPin, INPUT_PULLUP);
myDebouncer.setup();
}
void motorControl(){
analogWrite(MA_IA, DCSpeed);
analogWrite(MA_IB, 0);
}
void loop() {
int reading = myDebouncer.read();
if (reading == LOW) {
DCSpeed += 120;
if (DCSpeed > 255) DCSpeed = 0;
Serial.println(DCSpeed);
}
motorControl();
}
'arduino' 카테고리의 다른 글
Day4 07-tetris (0) | 2024.02.04 |
---|---|
Day4 06-joystick (0) | 2024.02.04 |
Day4 04-DCmotor, button (0) | 2024.02.04 |
Day4 03-DCmotor (0) | 2024.02.04 |
Day4 02-encoder (0) | 2024.02.04 |