arduino(22)
-
Day4 07-tetris
OLED와 조이스틱을 이용한 테트리스 게임 #include #include #include #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); const int restartButtonPin = 2; const int xPin = A0; const int yPin = A1; int xPos = 0; int yPos = 0; const int BLOCK_SIZE = 4; const int BLOCK_TYPES = 9; const int BOARD_WIDTH = 15; const int BOARD_HE..
2024.02.04 -
Day4 06-joystick
조이스틱으로 입력받아 시리얼 모니터에 출력하기 const int Xin = A0; const int Yin = A1; const int Keyin = 2; volatile bool isBtnPressed = false; void ISRBtn(){ isBtnPressed = true; } void setup() { // put your setup code here, to run once: pinMode(Keyin, INPUT_PULLUP); Serial.begin(9600); attachInterrupt(digitalPinToInterrupt(Keyin), ISRBtn, FALLING); } void loop() { // put your main code here, to run repeatedly: int..
2024.02.04 -
Day4 05-DCmotor, button 2
DC 모터와 버튼을 이용한 간이 선풍기 만들기 #include // 선풍기 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..
2024.02.04 -
Day4 04-DCmotor, button
버튼을 이용한 모터제어 const int MA_IA = 9; const int MA_IB = 10; const int btnStartPin = 2; const int btnStopPin = 3; volatile bool isStartPressed = false; volatile bool isStopPressed = false; void ISRButtonStart() { isStartPressed = true; Serial.println("Start pressed!"); } void ISRButtonStop() { isStopPressed = true; Serial.println("Stop pressed!"); } void setup() { // put your setup code here, to run ..
2024.02.04 -
Day4 03-DCmotor
DC모터를 연결하여 시리얼 모니터에 특정 문자입력에 따라 작동하는 코드 const int MA_IA = 9; const int MA_IB = 10; void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(MA_IA, OUTPUT); pinMode(MA_IB, OUTPUT); } void loop() { // put your main code here, to run repeatedly: if (Serial.available() > 0) { char data = Serial.read(); if (data == 'f') { analogWrite(MA_IA, 150); analogWrite(MA_IB, 0); } e..
2024.02.04 -
Day4 02-encoder
인터럽트를 사용하여 인코더의 펄스를 세는 코드 int encoderPin = 2; unsigned long oldTime = 0; unsigned long newTime = 0; volatile int count = 0; void ISREncoder() { count++; } void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(encoderPin, INPUT_PULLUP); attachInterrupt(INT0, ISREncoder, FALLING); } void loop() { // put your main code here, to run repeatedly: newTime = millis(); if (..
2024.02.04