arduino(22)
-
Day4 01-debounce
debounce를 이용한 LED제어 const int ledPin = 3; const int buttonPin = 2; int ledState = LOW; int buttonState = HIGH; int lastButtonState = HIGH; unsigned long lastDebounceTime = 0; unsigned long debounceDelay = 50; void setup() { // put your setup code here, to run once: pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT_PULLUP); digitalWrite(ledPin, ledState); } void loop() { // put your main code her..
2024.02.04 -
Day3 01-dht11
dht11에서 정보를 받아와 OLED에 출력하는 코드 // Humid : 습도값 // Temp : 온도 #include #include #include #define SCREEN_WIDTH 128 // OLED display width, in pixels #define SCREEN_HEIGHT 64 // OLED display height, in pixels #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 Adafruit_SSD1306 oled(SCREEN_..
2024.02.04 -
Day2 06_Debounce
디바운스를 이용해 버튼 누를때 생기는 노이즈의 영향을 받지않아 안정적이게 led 컨트롤 가능 const int buttonPin = 2; const int ledPin = 3; int ledState = LOW; int buttonState= HIGH; int lastButtonState = HIGH; unsigned long lastDebounceTime = 0; unsigned long debounceDelay = 50; void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, ledState); } void loop() { int reading = digitalRead(buttonPin)..
2024.01.18 -
Day2 05_IR
적외선 센서 출력 const int IRPin = 2; const int ledPin = 13; void setup() { // put your setup code here, to run once: pinMode(IRPin, INPUT); pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: int IRInput = digitalRead(IRPin); Serial.println(IRInput); }
2024.01.18 -
Day2 04_sonic
초음파 센서를 이용한 거리 출력 const int trigPin = 14; //A0 const int echoPin = 15; //A1 const int ledPin = 13; void setup() { // put your setup code here, to run once: pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop() { long distance = getDistance(); Serial.println(String(distance) + " cm"); if (distance < 15) { digitalWrite(ledPin, HIGH); } else {..
2024.01.18 -
Day2 03_sensor_led
센서의 값을 받아와서 범위에 따라 led 점등 const int analogPin = A0; const int ledPin[6] = {3,5,6,9,10,11}; void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: int sensorInput = analogRead(analogPin); // Serial.println(sensorInput); int level = map(sensorInput, 0, 1023, 0, 6); for(int i=0; i
2024.01.18