PROGRAMMING

실습 - 버튼, LED, PIR, PWM, 초음파, 온습도 본문

Raspberry

실습 - 버튼, LED, PIR, PWM, 초음파, 온습도

Raccoon2125 2020. 11. 3. 23:38

 ◎ LED, LED(BUTTON)

 ◎ RGB_LED

 ◎ PIR_SENSOR

 ◎ SENSOR (ARDUINO CODE)

	• SENSOR arduino code

int buttonState = 0;
int lastButtonState = 0; 
int buttonPushCounter = 0;
 
void setup()
{
  pinMode(2, INPUT);
  Serial.begin(9600);
 
  pinMode(13, OUTPUT);
}
 
void loop()
{
  // read the pushbutton input pin
  buttonState = digitalRead(2);
  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH, then the button
      // went from off to on
      buttonPushCounter += 1;
      Serial.println("on");
      Serial.print("number of button pushes: ");
      Serial.println(buttonPushCounter);
    } else {
      // if the current state is LOW, then the button
      // went from on to off
      Serial.println("off");
    }
    // delay a little bit to avoid debouncing
    delay(5); // Wait for 5 millisecond(s)
  }
  // save the current state as the last state, for
  // the next time through the loop
  lastButtonState = buttonState;
  // turns on the LED every four button pushes by
  // checking the modulo of the button push counter.
  // the modulo function gives you the remainder of
  // the devision of two numbers
  if (buttonPushCounter % 4 == 0) {
    digitalWrite(13, HIGH);
  } else {
    digitalWrite(13, LOW);
  }
}

 ◎ PWM

 ◎ 초음파 센서

 ◎ 온습도 센서

'Raspberry' 카테고리의 다른 글

실습 파일(I2C LCD, I2C_LCD_driver.py 포함)  (0) 2020.11.03
My Note  (0) 2020.11.03
라즈베리 관련 명령어  (0) 2020.11.03
I2C LCD - 참고 사이트  (0) 2020.11.03
Comments