목록전체 글 (418)
Creative Code
#include #include const int trig_pin = 9; const int echo_pin = 10; unsigned long echo_duration =0; void echoIsr(void) { static unsigned long echo_begin = 0; static unsigned long echo_end = 0; unsigned int echo_pin_state = digitalRead(echo_pin); if (echo_pin_state == HIGH) { echo_begin = micros(); } else { echo_end = micros(); echo_duration = echo_end - echo_begin; } } void timerIsr(void) { if (e..
#include const int BUZZER = 10; const int melody[] = {262,294,330,349,393,440,494,523,}; void setup() { // put your setup code here, to run once: Timer1.initialize(); Timer1.pwm(BUZZER,0); Timer1.setPwmDuty(BUZZER,100); for (int note = 0; note
#include const int LED = 10; // timer1 을 쓰기위해서는 9,10번핀에 연결 int ledflag = 0; void timerIsr(void) { if (ledflag == 0) { digitalWrite(LED,HIGH); ledflag = 1; } else { digitalWrite(LED,LOW); ledflag = 0; } } void setup() { // put your setup code here, to run once: pinMode(LED,OUTPUT); Timer1.initialize(1000000); //Timer1.pwm(LED,0); //timer1을 이용하여 pwm기능을 사용하는 경우 설정 Timer1.attachInterrupt(timerIsr); ..
const int trig_pin =11; const int echo_pin =12; void setup() { // put your setup code here, to run once: pinMode(trig_pin,OUTPUT); pinMode(echo_pin,INPUT); Serial.begin(115200); } void loop() { // put your main code here, to run repeatedly: digitalWrite(trig_pin,LOW); delayMicroseconds(2); digitalWrite(trig_pin,HIGH); delayMicroseconds(10); digitalWrite(trig_pin,LOW); long duration = pulseIn(ech..
#define V0 5.0 #define unit V0/1024 #define R1 10000.0 const int Xin = A0; const int Yin = A1; const int KEYin = 3; void setup() { // put your setup code here, to run once: Serial.begin(115200); pinMode(KEYin,INPUT_PULLUP); // 칩 내부에 있는 pull up 저항을 사용 } void loop() { // put your main code here, to run repeatedly: int Xval = analogRead(Xin); int Yval = analogRead(Yin); int buttonval = digitalRead(..
#define V0 5.0 #define unit V0/1024 #define R1 10000.0 const int Xin = A0; const int Yin = A1; const int KEYin = 3; void setup() { // put your setup code here, to run once: Serial.begin(115200); pinMode(KEYin,INPUT_PULLUP); // 칩 내부에 있는 pull up 저항을 사용 } void loop() { // put your main code here, to run repeatedly: int Xval = analogRead(Xin); int Yval = analogRead(Yin); int buttonval = digitalRead(..