Arduinoda yardım istiyen gelebilir

Arduino çok çok çokkk basit bence pıc den önce Arduino ile başlayın daha mantıklı hiç tecrübeniz yok ise
 
Merhaba, bir butonla 5 adet farklı frekans üretip lcd ekranda frekansı yazdırmam gerekiyor, 2 parça örnek koda sahibim ama ana koda nasıl adapte edeceğim konusunda destek rica edeceğim.
Kod:
const byte LED = 3;  // Timer 2 "B" output: OC2B



const long frequency = 12500L;  // Hz



void setup()

{

  pinMode (LED, OUTPUT);



  TCCR2A = _BV (WGM20) | _BV (WGM21) | _BV (COM2B1); // fast PWM, clear OC2B on compare

  TCCR2B = _BV (WGM22) | _BV (CS21);         // fast PWM, prescaler of 8

  OCR2A =  ((F_CPU / 8) / frequency) - 1;    // zero relative

  OCR2B = ((OCR2A + 1) / 2) - 1;             // 50% duty cycle

  }  // end of setup



void loop() { }





#include <Wire.h>

#include <LiquidCrystal_I2C.h>



LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display



int WhichScreen =1;   // This variable stores the current Screen number

boolean hasChanged = true;

const int buttonPin = 4;    // the number of the pushbutton pin

int buttonState;             // the current reading from the input pin

int lastButtonState = LOW;   // the previous reading from the input pin

unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled

unsigned long debounceDelay = 50;    // the debounce time; increase if the output flickers



void setup()

{

  lcd.init();// initialize the lcd

  lcd.backlight();

  pinMode(buttonPin, INPUT);

 

}

void loop()

{



  if (hasChanged == true) {

  

  switch(WhichScreen) {

    case 1:

    {

      firstScreen();

    }

      break;

  

    case 2:

      {

        secondScreen();

      }

      break;

  

    case 3:

      {

        thirdScreen();

      }

      break;

  

    case 4:

      {

        fourthScreen();

      }

      break;

  

    case 5:

      {

        fifthScreen();

      }

      break;

  

    case 6:

      {

        sixthScreen();

      }

      break;

    case 0:

      {

      

      }

      break;

    }

}



    //-------------------------------

    // BEGIN of the switch debouncing code

    int reading = digitalRead(buttonPin);

  if (reading != lastButtonState) {

    // reset the debouncing timer

    lastDebounceTime = millis();

  }



if ((millis() - lastDebounceTime) > debounceDelay) {

    // whatever the reading is at, it's been there for longer

    // than the debounce delay, so take it as the actual current state:



    // if the button state has changed:

    if (reading != buttonState) {

      buttonState = reading;



      // only toggle the LED if the new button state is HIGH

      if (buttonState == HIGH) {

        hasChanged = true;

        WhichScreen++;

      

      

      }

    } else {

      hasChanged = false;

    }

  }

  lastButtonState = reading;

  // END of the switch Debouncing code

  // --------------------------------------

  if (WhichScreen > 6){

    WhichScreen = 1;

  }

}



void firstScreen()

  {

   lcd.clear();

   lcd.setCursor(0,0); // Column, line

   lcd.print("This is screen 1");

   lcd.setCursor(0,1);

   lcd.print("On a menu system");

  }

void secondScreen()

  {

    lcd.clear();

    lcd.setCursor(0,0); // Column, line

    lcd.print("  Second screen");

    lcd.setCursor(0,1);

    lcd.print("of my menu !!");

  }

void thirdScreen()

  {

    lcd.clear();

    lcd.setCursor(0,0); // Column, line

    lcd.print("Hello, world!");

    lcd.setCursor(0,1);

    lcd.print("Third screen (3)");

  }

void fourthScreen()

  {

    lcd.clear();

    lcd.setCursor(0,0); // Column, line

    lcd.print("This is screen 4");

    lcd.setCursor(0,1);

    lcd.print("Just press btn");

  }

void fifthScreen()

  {

    lcd.clear();

    lcd.setCursor(0,0); // Column, line

    lcd.print("   Fifth screen");

    lcd.setCursor(0,1);

    lcd.print("i2C LCD screen");

  }

void sixthScreen()

  {

    lcd.clear();

    lcd.setCursor(0,0); // Column, line

    lcd.print("THE last screen");

    lcd.setCursor(0,1);

    lcd.print("  Sixth and last");

  }
 
Moderatör tarafında düzenlendi:
wifi den arduinoya seri data göndererek 2 adet motoru ileri geri kontrol etmem lazım.
LI200--sol motor ileri hız 200 şeklinde kodlar göndermek istiyorum
LG120 -- sol motor geri hız 120 şeklinde
RI080 --sag motor ileri hız 80
RG250 -- sağ motor geri hız 250

bu şekilde seriden data gönderiyorum ama bu kodları ayırıp analiz etme kısmını yapamadım

char buf;
buf = Serial.read();

burda buf değişkenini nasıl ayırabilirim
saygılar
 
Buf değişkeni seri porttan okunuyor
 
Merhaba arkadaşlar forumda yeni üyeyim arduino ile hobi amaçlı ilgileniyorum. Arduino ile kodlarımı güzelce çalıştırıyorum fakat tek sorun bunların bir bütün içinde çalıştıramıyorum. Yani 11 butonuna bastığımda o ses bitmeden 9 korna olarak girsin devreye ama 11 butonuna bastıktan sonra siren bittikten sonra korna giriyor. Birde hangi butona ne kadar basıyorsam o kadar çalsın istiyorum nasıl yapabilrim ?

KODLAR;

int buzz=10;
int siren=11;
int dat=9;
int kapat=12;
static unsigned long lastButtonTime = 0;

double angle_rad = PI/180.0;
double angle_deg = 180.0/PI;
void setup()
{




pinMode(10,OUTPUT);

pinMode(11,INPUT);
pinMode(9,INPUT);
pinMode(kapat,INPUT);







}


void loop()
{
butondurum12 = digitalRead(12);

if(((digitalRead(12))==(1 ))){
tone(10,50,125); // write to buzzer
delay(10);
}








if(((digitalRead(13))==(1 ))){
tone(10,50,125); // write to buzzer
delay(10);
}




if(((digitalRead(11))==(1 ))){

// Whoop down
for(int hz = 1800; hz > 450; hz-=3){
tone(buzz, hz, 15);
delay(5);
for(int m=0;m<=5;m++)
{
digitalWrite(m,LOW);
digitalWrite(m,HIGH);
}
}
}

_loop();
}



void _delay(float seconds){
long endTime = millis() + seconds * 1000;
while(millis() < endTime)_loop();
}
 
Çok ilkelce ama mantıklı bir yol geldi aklıma 10 sn bekleyi 10 a bölüp her sn de düğmeyi kontrol edebilir
 
Hocam size zahmet kodlara ekleyebilirseniz ya da nasıl bir kod ekleyebileceğimi söyleyebilirseniz çok makbule geçer
 
Her koddan sonra if kullanarak butonu kontrol edip tonu çalabilirsiniz
 
butondurum12 = digitalRead(12);

if(((digitalRead(12))==(HIGH))){


for(int hz = 200; hz < 400; hz+=50){
tone(10,82,20); // write to buzzer
delay(20);
}

}else {
digitalWrite(12,LOW);
delay(350);
}


else komutu olan yeri ekledim istediğimi şuan yapıyorum ama 3 butondan gelen sesin bir tanesi böyle öteki seslerde bozulma oluyor. yani o seslere bu kodu eklemediğim halde tık tık yapıp bitiyor
 
Sadece if yapın eğer butona basılmadı ise direk döngüye devam eder
 

Forum istatistikleri

Konular
128,190
Mesajlar
915,722
Kullanıcılar
449,959
Son üye
çor-man

Yeni konular

Geri
Üst