본문 바로가기

스위치버튼

버튼스위치로 숫자 변경하기 준비물 - 7segment 1개 - 버튼스위치 2개 - 10㏀ 저항 2개 - 220Ω 저항 1개 코드 int digit = 0; byte digits[10][7] = { {1, 1, 1, 1, 1, 1, 0}, {0, 1, 1, 0, 0, 0, 0}, {1, 1, 0, 1, 1, 0, 1}, {1, 1, 1, 1, 0, 0, 1}, {0, 1, 1, 0, 0, 1, 1}, {1, 0, 1, 1, 0, 1, 1}, {0, 0, 1, 1, 1, 1, 1}, {1, 1, 1, 0, 0, 0, 0}, {1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 0, 0, 1, 1}, }; const int minusButtonPin = 2; const int plusButtonPin = 3; void setup(.. 더보기
버튼스위치를 사용하여 3색 LED 색 바꾸기 준비물 - 10㏀ 저항 3개 - 버튼스위치 3개 - 3색 LED 1개 코드 // LED 출력 값(0~255) int redVal = 0; int greenVal = 0; int blueVal = 0; // 값 입력 핀 const int inputRedPin = 2; const int inputGreenPin = 3; const int inputBluePin = 4; // LED 출력 핀 const int ledRedPin = 11; const int ledGreenPin = 10; const int ledBluePin = 9; void setup() { // 핀 모드 설정 pinMode(inputRedPin, INPUT); pinMode(inputGreenPin, INPUT); pinMode(inputB.. 더보기
버튼스위치를 사용하여 LED 켜기 준비물 - 1㏀ 저항 1개 - 220Ω 저항 1개 - 버튼스위치 1개 - LED 1개(색 상관없음) 코드 const int ledPin = 13; // 출력핀(LED 연결) const int inputPin = 8; // 입력핀(스위치연결) void setup() { // 핀 모드 설정 pinMode(ledPin, OUTPUT); pinMode(inputPin, INPUT); } void loop() { // 입력핀의 값을 읽음 int readVal = digitalRead(inputPin); // 조건에 따라 LED on/off if(readVal == HIGH) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } } 시연 영상 - .. 더보기