#include //SoftwareSerial(RXD PIN, TXD PIN); SoftwareSerial BTSerial(2,3); void setup() { Serial.begin(9600); BTSerial.begin(9600); pinMode(5, OUTPUT); pinMode(6, OUTPUT); pinMode(7, OUTPUT); } void loop() { if(BTSerial.available()) { int btData = BTSerial.read(); Serial.write(btData); ledOn(btData); } if(Serial.available()) { BTSerial.write(Serial.read()); } } void ledOn(int btData) { if(btData..
#include int potVal; int angle; Servo myServo; void setup() { myServo.attach(8, 640, 2400); Serial.begin(9600); } void loop() { potVal = analogRead(A0); angle = (potVal / 1023.0) * 180.0; myServo.write(angle); Serial.print("angle : "); Serial.println(angle); delay(15); }
long duration, Cm, In; void setup() { Serial.begin(9600); pinMode(9, INPUT); pinMode(10, OUTPUT); digitalWrite(10, LOW); } void loop() { digitalWrite(10, HIGH); delayMicroseconds(10); digitalWrite(10, LOW); duration = pulseIn(9, HIGH); Cm = duration / 29.1 / 2; In = duration / 74 / 2; Serial.print("Cm = "); Serial.print(Cm); Serial.print(" , In = "); Serial.println(In); delay(100); }
#define CW HIGH #define CCW LOW void setup() { pinMode(7, OUTPUT); pinMode(8, OUTPUT); pinMode(9, OUTPUT); } void loop() { int motorSpeed = analogRead(A0) / 4; setMotor(motorSpeed, CW); delay(2000); setMotorStop(); delay(2000); setMotor(motorSpeed, CCW); delay(2000); setMotorStop(); delay(2000); } void setMotor(int motorSpeed, boolean motirDir) { analogWrite(9, motorSpeed); digitalWrite(8, motir..
// 아날로그 입력을 통한 DC모터 속도 제어, 트렌지스터 S8050 void setup() { pinMode(11, OUTPUT); } void loop() { analogWrite(11, 50); // analogWrite 값에 따라 모터 속도가 변한다 } // 가변저항을 이용한 DC모터 속도 제어 void setup() { pinMode(11, OUTPUT); } void loop() { analogWrite(11, analogRead(0)/4); } // 선풍기 #define STOP 0 #define SPEED1 80 #define SPEED2 150 #define SPEED3 255 byte switchMode = 0; void setup() { pinMode(11, OUTPUT); pinMo..
int bell = 0; //도레미파솔라시 unsigned int frqArray[7] = {262, 294, 330, 349, 392, 440, 494}; //똑같아요 동요 박자 int signatures[20] = {4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2}; //똑같아요 동요 음계 int scale[20] = {0, 2, 4, 0, 2, 4, 5, 5, 5, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0}; void setup() { pinMode(2, INPUT_PULLUP); pinMode(11, OUTPUT); pinMode(12, OUTPUT); digitalWrite(11, HIGH); } void loop() { ..
int piezoPin = 12; //도레미파솔라시 unsigned int frqArray[7] = {262, 294, 330, 349, 392, 440, 494}; //똑같아요 동요 박자 int signatures[20] = {4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2}; //똑같아요 동요 음계 int scale[20] = {0, 2, 4, 0, 2, 4, 5, 5, 5, 4, 3, 3, 3, 2, 2, 2, 1, 1, 1, 0}; void setup() { pinMode(piezoPin, OUTPUT); } void loop() { for(int i = 0 ; i < 20 ; i++) { unsigned long duration = 100..
#include //ROM(비휘발성 메모리) 활용 int swCount = 0; int swBuf = 0; unsigned char color[8][3] = { // R G B { 0, 0, 0} // OFF , {255, 0, 0} // Red , { 0, 255, 0} // Green , { 0, 0, 255} // Blue , {255, 255, 0} // Yellow , {255, 0, 255} // magenta , { 0, 255, 255} // cyan , {255, 255, 255} // white }; void setup() { pinMode(9, OUTPUT); pinMode(10, OUTPUT); pinMode(11, OUTPUT); pinMode(2, INPUT_PULLUP); Se..
// 아날로그 입력을 통한 LED 밝기 제어 int analogValue = 0; void setup() { pinMode(11, OUTPUT); } void loop() { if(analogValue == 255) analogValue = 0; analogValue += 5; analogWrite(11, analogValue); delay(100); } // 가변저항을 통한 LED 밝기 제어 void setup() { Serial.begin(9600); pinMode(11, OUTPUT); } void loop() { int adcData = analogRead(A0); int analogValue = map(adcData, 0, 1023, 0, 255); Serial.println(analogValu..