ถามครับผมอยากเอาโค้ดนี้มาใช้กับ SD Card Module ใน Arduino UNO R3 อะครับ ผมควรจะเขียนโค้ดยังไงครับเพื่อที่จะให้ตัว SD Card Module จดจำโค้ดข้างล่างนี้อะครับ
//#include <LiquidCrystal.h>
#include <Servo.h>
//LiquidCrystal lcd{12, 11, 5, 4, 3, 2}; // Ultrasonice Sensor Example
Servo servo;
int trig=9;
int echo=8;
int duration;
float distance;
float netez;
int buzz = 10;
void setup()
{
//lcd.begin(16, 2); // set up the LCD's number of colurna and rowa:
//lcd.print("Svolt solution ");
Serial.begin(9600);
servo.attach(6);
pinMode(trig, OUTPUT);
digitalWrite(trig, LOW);
delayMicroseconds(2);
pinMode(echo, INPUT);
delay(6000);
pinMode(buzz, OUTPUT); // BUZZER IS THE DIGITAL ONE
Serial.println("Distance:");
}
void loop()
{
int i=20; // YOU CAN SET THE ANY VALUE TO CHANGE THE FREQUENCY
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
distance = duration/58;
Serial.print(distance);
Serial.print("on");
Serial.print("\n"); // THIS IS REQUIRED TO CALCULATE THE DISTANCE IN CENTIMETERS
if(distance<=100 && distance >=1) // BUZZER WILL START BUZZING IF THE DISTANCE IS BETWEEN 1 TO 100 CM
{
i=distance*i; // THIS THE MAIN ALGORITHM
digitalWrite(buzz, HIGH);
delay(i); // SO THE DELAY BETWEEN SWITCHING WILL CHANGE ACCORDING TO THE DISTANCE
digitalWrite(buzz, LOW);
delay(i);
}
delay(10);
}
ถามการใช้ SD Card Module ใน Arduino UNO R3 อะครับ ผมควรจะเขียนโค้ดยังไงให้มันจำโค้ดที่ผมต้องการให้จำอะครับ
//#include <LiquidCrystal.h>
#include <Servo.h>
//LiquidCrystal lcd{12, 11, 5, 4, 3, 2}; // Ultrasonice Sensor Example
Servo servo;
int trig=9;
int echo=8;
int duration;
float distance;
float netez;
int buzz = 10;
void setup()
{
//lcd.begin(16, 2); // set up the LCD's number of colurna and rowa:
//lcd.print("Svolt solution ");
Serial.begin(9600);
servo.attach(6);
pinMode(trig, OUTPUT);
digitalWrite(trig, LOW);
delayMicroseconds(2);
pinMode(echo, INPUT);
delay(6000);
pinMode(buzz, OUTPUT); // BUZZER IS THE DIGITAL ONE
Serial.println("Distance:");
}
void loop()
{
int i=20; // YOU CAN SET THE ANY VALUE TO CHANGE THE FREQUENCY
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
duration = pulseIn(echo, HIGH);
distance = duration/58;
Serial.print(distance);
Serial.print("on");
Serial.print("\n"); // THIS IS REQUIRED TO CALCULATE THE DISTANCE IN CENTIMETERS
if(distance<=100 && distance >=1) // BUZZER WILL START BUZZING IF THE DISTANCE IS BETWEEN 1 TO 100 CM
{
i=distance*i; // THIS THE MAIN ALGORITHM
digitalWrite(buzz, HIGH);
delay(i); // SO THE DELAY BETWEEN SWITCHING WILL CHANGE ACCORDING TO THE DISTANCE
digitalWrite(buzz, LOW);
delay(i);
}
delay(10);
}