공설입 코딩 예제
공설입 코딩 예제
void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
void loop() {
digitalWrite(trigpin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
Serial.print(distance);
Serial.println("cm");
// 수정한 값을 출력
delay(500);
}
네오픽셀
#include <Adafruit_NeoPixel.h>
// 아두이노 초기화
void setup()
funnyNeo.setBrightness(ledBright); // 밝기 설정 ( 0 ~ 255 )
funnyNeo.begin(); // 네오픽셀 시작
void loop()
int i;
//빨간색 1 바퀴 회전
funnyNeo.setPixelColor(i, colorValue);
funnyNeo.show();
delay(50);
}
// 녹색 1 바퀴 회전
funnyNeo.setPixelColor(i, colorValue);
funnyNeo.show();
delay(50);
// 파랑색 1 바퀴 회전
funnyNeo.setPixelColor(i, colorValue);
funnyNeo.show();
delay(50);
// 하얀색 1 바퀴 회전
funnyNeo.setPixelColor(i, colorValue);
funnyNeo.show();
delay(50);
리얼타임
// CONNECTIONS:
#include <ThreeWire.h>
#include <RtcDS1302.h>
RtcDS1302<ThreeWire> Rtc(myWire);
void setup ()
Serial.begin(57600);
Serial.print("compiled: ");
Serial.print(__DATE__);
Serial.println(__TIME__);
Rtc.Begin();
printDateTime(compiled);
Serial.println();
if (!Rtc.IsDateTimeValid())
// Common Causes:
// 1) first time you ran and the device wasn't running yet
Rtc.SetDateTime(compiled);
if (Rtc.GetIsWriteProtected())
Rtc.SetIsWriteProtected(false);
if (!Rtc.GetIsRunning())
Rtc.SetIsRunning(true);
Rtc.SetDateTime(compiled);
Serial.println("RTC is the same as compile time! (not expected but all is fine)");
}
void loop ()
printDateTime(now);
Serial.println();
if (!now.IsValid())
// Common Causes:
// 1) the battery on the device is low or even missing and the power line was
disconnected
char datestring[20];
snprintf_P(datestring,
countof(datestring),
PSTR("%02u/%02u/%04u %02u:%02u:%02u"),
dt.Month(),
dt.Day(),
dt.Year(),
dt.Hour(),
dt.Minute(),
dt.Second() );
Serial.print(datestring);
무드등 조작 버튼
int ledState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
void loop(){
buttonState = digitalRead(buttonPin);
if(ledState == 0)
digitalWrite(ledPin, HIGH);
ledState=1;
else
digitalWrite(ledPin, LOW);
ledState=0;
}
else
prevButtonState = buttonState;