DHT 라이브러리 추가 https://github.com/markruys/arduino-DHT #include DHT dht; void setup() { Serial.begin(9600); dht.setup(2); } void loop() { delay(dht.getMinimumSamplingPeriod()); float temp = dht.getTemperature(); float humidity = dht.getHumidity(); Serial.print("temp : "); Serial.print(temp, 2); Serial.print(" C"); Serial.print(" ___ humidity : "); Serial.print(humidity, 2); Serial.println(" %"); }
#include #define A 0.001129148 #define B 0.000234125 #define C 0.0000000876741 #define Vin 5.0 #define R2 10000.0 void setup() { Serial.begin(9600); } double SteinharFart(double R) { //NTC 온도 변환 공식 double logR = log(R); double logR3 = pow(logR, 3); return 1.0 / (A + B * logR + C * logR3); } void loop() { int adcData = analogRead(0); double Vout = (adcData * Vin) / 1023; double Rth = ((Vin * R2) ..
int prevCdsValue = 0; void setup() { Serial.begin(9600); pinMode(12, OUTPUT); digitalWrite(12, LOW); } void loop() { int adcData = analogRead(0); if(abs(prevCdsValue - adcData) > 100) { prevCdsValue = adcData; Serial.println(adcData); if(adcData > 300) { digitalWrite(12, HIGH); }else { digitalWrite(12, LOW); } } }
교육자료 - 웹시스템 성능 튜닝 이해하기 프리젠테이션 from Opennaru, Inc.
// 가변저항 값 읽어 오기 int adcPin = A0; int preAdcData = 0; int errLimit= 5; void setup() { Serial.begin(9600); } void loop() { int adcData = analogRead(adcPin); // 0~1023 아날로그 값 read if(preAdcData - errLimit > adcData || preAdcData + errLimit < adcData) { preAdcData = adcData; Serial.println(adcData); } } // 가번저항 값을 통한 LED 제어 int adcPin = A0; int ledPin[] = {6, 7, 8, 9, 10, 11, 12, 13}; void setup() {..
// 터미널 창을 통해 값을 전달 하여 LED 제어 int ledPin = 12; int incomingByte = 0; void setup() { pinMode(ledPin, OUTPUT); Serial.begin(9600); } void loop() { if(Serial.available() > 0) { incomingByte = Serial.read(); Serial.print("incomingByte = "); Serial.println(incomingByte); if(incomingByte == '1') { digitalWrite(ledPin, HIGH); }else if(incomingByte == '0') { digitalWrite(ledPin, LOW); } } } //serialEvent..
unsigned int displayNum = 0; byte fndData[10][7] = { {0, 0, 0, 0, 0, 0, 1}, //0 {1, 0, 0, 1, 1, 1, 1}, //1 {0, 0, 1, 0, 0, 1, 0}, //2 {0, 0, 0, 0, 1, 1, 0}, //3 {1, 0, 0, 1, 1, 0, 0}, //4 {0, 1, 0, 0, 1, 0, 0}, //5 {0, 1, 0, 0, 0, 0, 0}, //6 {0, 0, 0, 1, 1, 1, 1}, //7 {0, 0, 0, 0, 0, 0, 0}, //8 {0, 0, 0, 0, 1, 0, 0}, //9 }; void setup() { for(int i = 6 ; i < 14 ; i++) { pinMode(i, OUTPUT); digit..
boolean ledFlag = LOW; void setup() { pinMode(12, OUTPUT); pinMode(2, INPUT_PULLUP); attachInterrupt(0, interrupt, FALLING); // RISING, FALLING, CHANGE digitalWrite(12, LOW); } void loop() { } void interrupt() { ledFlag = !ledFlag; digitalWrite(12, ledFlag); }
// 스위치로 LED ON OFF // 스위치 오동작은 캐패시터로 해결 int ledPin = 12; int switchPin = 7; int swStatus = LOW; int ledStatus = LOW; void setup() { pinMode(ledPin, OUTPUT); pinMode(switchPin, INPUT_PULLUP); digitalWrite(ledPin, LOW); } void loop() { if(digitalRead(switchPin) == LOW && swStatus == LOW) { swStatus = HIGH; }else if(digitalRead(switchPin) == HIGH && swStatus == HIGH) { swStatus = LOW; ledStatus = !..