Arduino kodları nasıl birleştirilir?

378894

Hectopat
Katılım
23 Ekim 2020
Mesajlar
381
Çözümler
1
Arkadaşlar merhaba ben Arduino ile kod yazdım fakat bunları ayrı ayrı yaptım. Bunları rica etsem birleştirebilir misiniz?

Kodlar:

1.Mesafe Sensörü Kodu

Kod:
#İnclude <LiquidCrystal_I2C.h>



LiquidCrystal_I2C LCD(0x27, 16, 2);



Byte degree_symbol[8] =



{



0B00111,



0B00101,



0B00111,



0B00000,



0B00000,



0B00000,



0B00000,



0B00000



};



İnt gate=11;



Volatile unsigned long duration=0;



Unsigned char i[5];



Unsigned int j[40];



Unsigned char value=0;



Unsigned answer=0;



İnt z=0;



İnt b=1;



Void setup()



{



lcd.init();



lcd.init();



lcd.backlight();



LCD. Print("Temp = ");



LCD. SetCursor(0, 1);



LCD. Print("Humidity = ");



LCD. CreateChar(1, degree_symbol);



LCD. SetCursor(9, 0);



LCD. Write(1);



LCD. Print("C");



LCD. SetCursor(13, 1);



LCD. Print("%");



}



Void loop()



{



Delay(1000);



While(1)



{



Delay(1000);



PinMode(gate, OUTPUT);



DigitalWrite(gate, LOW);



Delay(20);



DigitalWrite(gate, HIGH);



PinMode(gate, INPUT_PULLUP);



Duration=pulseIn(gate, LOW);



İf(duration <= 84 && duration >= 72)



{



While(1)



{



Duration=pulseIn(gate, HIGH);



İf(duration <= 26 && duration >= 20){



Value=0;}



Else if(duration <= 74 && duration >= 65){



Value=1;}



Else if(z==40){



Break;}



İ[z/8]|=value<<(7- (z%8));



J[z]=value;



Z++;



}



}



Answer=i[0]+i[1]+i[2]+i[3];



İf(answer==i[4] && answer!=0)



{



LCD. SetCursor(7, 0);



LCD. Print(i[2]);



LCD. SetCursor(11, 1);



LCD. Print(i[0]);



}



Z=0;



İ[0]=i[1]=i[2]=i[3]=i[4]=0;



}



}

LED İle Timer Kodum

Kod:
İnt AnaLed = 13;



İnt LED3 = 10;



İnt LED1 = 11;



İnt LED2 = 12;



Unsigned long Ti'me;



Void setup(){



PinMode(Led, OUTPUT);



PinMode(Led1, OUTPUT);



PinMode(Led2, OUTPUT);



PinMode(Led3, OUTPUT);



Serial. Begin(9600);



}



Void loop()



{



DigitalWrite(Led, HIGH);



Serial. Print("Time: ");



Ti'me = millis();



Serial. Println(time);



Delay(500);



İf (time > 100) {



Serial. Print ("Timer has ended ");



DigitalWrite(Led3, HIGH);



} Else;



DigitalWrite(AnaLed, LOW);



Delay (500);



DigitalWrite(Led, HIGH);



Serial. Print("Time: ");



Ti'me = millis();



Serial. Println(time);



Delay(500);



İf (time > 200) {



Serial. Print ("Timer has ended ");



DigitalWrite(Led1, HIGH);



} Else;



DigitalWrite(AnaLed, LOW);



Delay (500);



DigitalWrite(Led, HIGH);



Serial. Print("Time: ");



Ti'me = millis();



Serial. Println(time);



Delay(500);



İf (time > 300) {



Serial. Print ("Timer has ended ");



DigitalWrite(Led2, HIGH);



} Else;



DigitalWrite(AnaLed, LOW);



Delay (500);



}

Sıcaklık Ölçüp I2C Ekrana yazdıran kodum:

Kod:
#İnclude <LiquidCrystal_I2C.h>



LiquidCrystal_I2C LCD(0x27, 16, 2);



Byte degree_symbol[8] =



{



0B00111,



0B00101,



0B00111,



0B00000,



0B00000,



0B00000,



0B00000,



0B00000



};



İnt gate=11;



Volatile unsigned long duration=0;



Unsigned char i[5];



Unsigned int j[40];



Unsigned char value=0;



Unsigned answer=0;



İnt z=0;



İnt b=1;



Void setup()



{



lcd.init();



lcd.init();



lcd.backlight();



LCD. Print("Temp = ");



LCD. SetCursor(0, 1);



LCD. Print("Humidity = ");



LCD. CreateChar(1, degree_symbol);



LCD. SetCursor(9, 0);



LCD. Write(1);



LCD. Print("C");



LCD. SetCursor(13, 1);



LCD. Print("%");



}



Void loop()



{



Delay(1000);



While(1)



{



Delay(1000);



PinMode(gate, OUTPUT);



DigitalWrite(gate, LOW);



Delay(20);



DigitalWrite(gate, HIGH);



PinMode(gate, INPUT_PULLUP);



Duration=pulseIn(gate, LOW);



İf(duration <= 84 && duration >= 72)



{



While(1)



{



Duration=pulseIn(gate, HIGH);



İf(duration <= 26 && duration >= 20){



Value=0;}



Else if(duration <= 74 && duration >= 65){



Value=1;}



Else if(z==40){



Break;}



İ[z/8]|=value<<(7- (z%8));



J[z]=value;



Z++;



}



}



Answer=i[0]+i[1]+i[2]+i[3];



İf(answer==i[4] && answer!=0)



{



LCD. SetCursor(7, 0);



LCD. Print(i[2]);



LCD. SetCursor(11, 1);



LCD. Print(i[0]);



}



Z=0;



İ[0]=i[1]=i[2]=i[3]=i[4]=0;



}



}
 
Son düzenleyen: Moderatör:
Yani 3 kodu bir araya toplamak kastettiğim, kodlar için kusura bakmayın hemen atacağım.
1. Mesafe Sensörü


#define echoPin 6
#define trigPin 7
#define buzzerPin 8

int maximumRange = 60;
int minimumRange = 0;



void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(buzzerPin, OUTPUT);

}

void loop()
{

int olcum = mesafe(maximumRange, minimumRange);
melodi(olcum*10);

}

int mesafe(int maxrange, int minrange)
{
long duration, distance;

digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);
distance = duration / 58.2;
delay(50);

if(distance >= maxrange || distance <= minrange)
return 0;
return distance;
}

int melodi(int dly)
{
tone(buzzerPin, 440);
delay(dly);
noTone(buzzerPin);
delay(dly);

}


2. Led İle Timer

int AnaLed = 13;
int Led3 = 10;
int Led1 = 11;
int Led2 = 12;
unsigned long time;



void setup(){
pinMode(Led, OUTPUT);
pinMode(Led1, OUTPUT);
pinMode(Led2, OUTPUT);
pinMode(Led3, OUTPUT);
Serial.begin(9600);
}
void loop()
{
digitalWrite(Led, HIGH);
Serial.print("Time: ");
time = millis();
Serial.println(time);
delay(500);
if (time > 100) {
Serial.print ("Timer has ended ");
digitalWrite(Led3, HIGH);
} else;
digitalWrite(AnaLed, LOW);
delay (500);


digitalWrite(Led, HIGH);
Serial.print("Time: ");
time = millis();
Serial.println(time);
delay(500);
if (time > 200) {
Serial.print ("Timer has ended ");
digitalWrite(Led1, HIGH);
} else;
digitalWrite(AnaLed, LOW);
delay (500);


digitalWrite(Led, HIGH);
Serial.print("Time: ");
time = millis();
Serial.println(time);
delay(500);
if (time > 300) {
Serial.print ("Timer has ended ");
digitalWrite(Led2, HIGH);
} else;
digitalWrite(AnaLed, LOW);
delay (500);
}

3. Sıcaklık Ölçer

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
byte degree_symbol[8] =
{
0b00111,
0b00101,
0b00111,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
int gate=11;
volatile unsigned long duration=0;
unsigned char i[5];
unsigned int j[40];
unsigned char value=0;
unsigned answer=0;
int z=0;
int b=1;
void setup()
{
lcd.init();
lcd.init();
lcd.backlight();
lcd.print("Temp = ");
lcd.setCursor(0,1);
lcd.print("Humidity = ");
lcd.createChar(1, degree_symbol);
lcd.setCursor(9,0);
lcd.write(1);
lcd.print("C");
lcd.setCursor(13,1);
lcd.print("%");
}

void loop()
{

delay(1000);
while(1)
{
delay(1000);
pinMode(gate,OUTPUT);
digitalWrite(gate,LOW);
delay(20);
digitalWrite(gate,HIGH);
pinMode(gate,INPUT_PULLUP);


duration=pulseIn(gate, LOW);
if(duration <= 84 && duration >= 72)
{
while(1)
{
duration=pulseIn(gate, HIGH);

if(duration <= 26 && duration >= 20){
value=0;}

else if(duration <= 74 && duration >= 65){
value=1;}

else if(z==40){
break;}

i[z/8]|=value<<(7- (z%8));
j[z]=value;
z++;
}
}
answer=i[0]+i[1]+i[2]+i[3];

if(answer==i[4] && answer!=0)
{
lcd.setCursor(7,0);
lcd.print(i[2]);
lcd.setCursor(11,1);
lcd.print(i[0]);
}

z=0;
i[0]=i[1]=i[2]=i[3]=i[4]=0;
}
}
 
Uyarı! Bu konu 5 yıl önce açıldı.
Muhtemelen daha fazla tartışma gerekli değildir ki bu durumda yeni bir konu başlatmayı öneririz. Eğer yine de cevabınızın gerekli olduğunu düşünüyorsanız buna rağmen cevap verebilirsiniz.

Technopat Haberler

Yeni konular

Geri
Yukarı