크리에이티브 프로젝트
예술과 기술의 만남(반짝이는 팝아트 자화상 만들기)
오즈랩
2024. 10. 10. 08:24
반응형
- 아두이노 소스코드
int TOUCH_SENSOR_PIN = 2; // D2
int led1 = 8; // D8
int led2 = 9; // D9
int led3 = 10; // D10
int led4 = 11; // D11
int led5 = 12; // D12
// variables will change:
int ledState = LOW; // the current state of LED
int lastTouchState; // the previous state of touch sensor
int currentTouchState; // the current state of touch sensor
void setup(){
unsigned char i;
Serial.begin(9600);
pinMode(TOUCH_SENSOR_PIN, INPUT);
for(i=8;i<=12;i++)//디지털IO 8~12번까지 출력모드로 설정합니다.
pinMode(i,OUTPUT);// i번째 핀을 출력모드로 설정합니다.
currentTouchState = digitalRead(TOUCH_SENSOR_PIN);
}
void loop() {
unsigned char j;
lastTouchState = currentTouchState; // save the last state
currentTouchState = digitalRead(TOUCH_SENSOR_PIN); // read new state
if(lastTouchState == LOW && currentTouchState == HIGH) {
Serial.println("The sensor is touched");
// toggle state of LED
ledState = !ledState;
// control LED arccoding to the toggled state
for(j=8;j<=12;j++){
digitalWrite(j, ledState);
delay(100);
}
}
}
반응형