목록Arduino (21)
printf("ho_tari\n");
#include #include const int trig_pin = 11; const int echo_pin = 12; int start_flag = 1; 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 timer..
#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,512); for(int note=0; note
#include const int LED = 5; int ledFlag = 0; void timerIsr(void) { if(ledFlag == 0){ digitalWrite(LED, HIGH); ledFlag = 1; } else if(ledFlag == 1){ 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); // Timer1 인..
#include #include // ECHO pin #define ECHO_INPUT 2 // TRIG pin #define TRIG_OUTPUT 3 // update interval, make sure to keep it above 20ms #define ULTRASONIC_TIMER_US 500000 // the time the pulse was sent volatile unsigned long ultrasonic_echo_start = 0; // the distance once it's been measured volatile unsigned long ultrasonic_distance = 0; void ultrasonicPulse(){ digitalWrite(TRIG_OUTPUT, HIGH); ..
const int BUZZER = 10; const int note[9] = {-1, 262, 294, 330, 349, 393, 440, 494, 523}; void setup() { // put your setup code here, to run once: Serial.begin(115200); } void loop() { // put your main code here, to run repeatedly: if(Serial.available()) { char userInput = Serial.read(); if('1'
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); } void loop() { // put your main code here, to run repeatedly: int xVal = analogRead(Xin); int yVal = analogRead(Yin); int buttonVal = digitalRead(KEYin); Serial.print("X= "); Serial.println(xVal, DEC); Serial.print("Y= "); Seri..
#define V0 5.0 #define unit V0/1024.0 #define R1 1000.0 const int analogPin = A0; const int LED_0 = 3; void setup() { // put your setup code here, to run once: Serial.begin(115200); pinMode(LED_0, OUTPUT); } void loop() { // put your main code here, to run repeatedly: int analogValue = analogRead(analogPin); float V2 = analogValue * unit; float R2 = (V2 * R1) / (V0 - V2); Serial.print(analogValu..
const uint8_t SW_0 = 2; const uint8_t LED_0 = 13; const uint8_t SW_1 = 3; const uint8_t LED_1 = 12; int led_flag_0 = 0; // 0 : OFF, 1 : ON int led_flag_1 = 0; // 사용자 함수 void SW0_Pressed(void) { if (led_flag_0 == 0) { led_flag_0 = 1; } else { led_flag_0 = 0; } } void SW1_Pressed(void) { if (led_flag_1 == 0) { led_flag_1 = 1; } else { led_flag_1 = 0; } } void setup() { // put your setup code here,..