아두이노22 3색 LED #define PIN_RED11 #define PIN_GREEN10 #define PIN_BLUE9 void mode1(); void mode2(); void mode3(); void setMode(char); byte R = 255, G = 0, B = 0, k = 0, mod = 0; void (*func)(); void setup() { Serial.begin(9600); pinMode(PIN_RED, OUTPUT); pinMode(PIN_GREEN, OUTPUT); pinMode(PIN_BLUE, OUTPUT); func = mode2; } void loop() { func(); if (Serial.available() > 0) { delay(3); char c = Serial.read(); se.. 아두이노 2022. 1. 17. 8 x 8 dot Matrix 코드 1 : 문자열을 출력하는 코드 #include "LedControlMS.h" #define DATA_IN 4 #define CLK3 #defineCS2 #define NBR_MTX 1 //number of matrices LedControl lc=LedControl(DATA_IN, CLK, CS, NBR_MTX); String str="Serial Input is Ready!"; String inputStr; void setup() { Serial.begin(9600); for (int i=0; i< NBR_MTX; i++) { lc.shutdown(i,false); /* Set the brightness to a medium values */ lc.setIntensity(i,8); /* and c.. 아두이노 2022. 1. 17. PWM #define PIN_PWM 9 int brightness = 0; int step = 5; void setup() { pinMode(PIN_PWM, OUTPUT); } void loop() { analogWrite(PIN_PWM, brightness); brightness += step; if ((brightness >= 255)|| (brightness 아두이노 2022. 1. 17. 단순 버튼 입력 int PIN_IN = 2; int PIN_OUT = 13; byte input; void setup() { Serial.begin(9600); pinMode(PIN_IN, INPUT); pinMode(PIN_OUT, OUTPUT); Serial.println("Start"); } void loop() { if(digitalRead(PIN_IN)) { Serial.println("ON"); digitalWrite(PIN_OUT, HIGH); }else{ Serial.print("*"); digitalWrite(PIN_OUT, LOW); } delay(200); } 아두이노 2022. 1. 17. LED LED가 1초마다 깜빡깜빡거리는 예제 출처 : https://www.arduino.cc/en/Main/Products https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink 실행 파일 명 : Output_LED_Blink 아두이노 2022. 1. 17. 건반 만들기 연결 상태 : 동작 : 키보드를 누르면 소리가 남 코드 : (주의! pitches.h가 해당 폴더에 있어야 함) #include "pitches.h" int melody[] = { NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 }; // 4 = 4분음표, 8 = 8분음표: int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 }; void setup() { Serial.begin(9600); for (int i = 0; i < 8; i++) { int noteDuration = 1000 / noteDurations[i]; tone(8, melody[i], noteDuration); delay(noteDur.. 아두이노 2022. 1. 17. 서보모터 SG90 부품 특성 : 코드 : #include #define PIN_PWM 9 #define MIN 0 #define MAX 180 #define MODE 0 void UpAndDown(); void OrderBySerial(); void setMode(int mode); Servo moter; String readString; String wBuf; int theta=0; int step = 5; void (*func)() = UpAndDown; void setup() { Serial.begin(9600); moter.attach(PIN_PWM, MIN,MAX); moter.writeMicroseconds(20); setMode(0); } void setMode(int mode) { switch(mode) {.. 아두이노 2022. 1. 17. 조이스틱 AxisJoystic 코드 정보 : (주의! 출력이 서보모터와 연동되어 있습니다.) #include #include #include #define PIN_PWM 9 #define MIN 0 #define MAX 180 #define SW_PIN 5 #define VRX_PIN A1 #define VRY_PIN A2 Joystick* joystic; Servo moter; int theta; void setup() { Serial.begin(9600); joystic = new AxisJoystick(SW_PIN, VRX_PIN, VRY_PIN); moter.attach(PIN_PWM, MIN,MAX); moter.writeMicroseconds(20); } void loop() { Serial.print(joystic->re.. 아두이노 2022. 1. 17. 온도, 습도 센서 (KY-015) int DHpin = 8; // input/output pin byte dat[5]; byte read_data() { byte i = 0; byte result = 0; for (i = 0; i < 8; i++) { while (digitalRead(DHpin) == LOW); // wait 50us delayMicroseconds(30); //The duration of the high level is judged to determine whether the data is '0' or '1' if (digitalRead(DHpin) == HIGH) result |= (1 아두이노 2022. 1. 17. 아날로그 입력 아두이노 2022. 1. 17. 이전 1 2 다음