اطلاعیه

Collapse
No announcement yet.

ولوم کنترل از راه دور با پتانسیومتر دیجیتال

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    ولوم کنترل از راه دور با پتانسیومتر دیجیتال

    سلام دوستان. من یه پتانسیومتر دیجیتال x9c104s دارم که میخواستم اونو با آردوینو نانو و گیرنده ir به اسپیکر خودم وصل کنم و ولوم رو با کنترل تنظیم کنم.
    با ترکیب چند کد از اینترنت تونستم که این کار رو با کلید فیزیکی انجام بدم . تو این پروژه توی دوتا قسمت با مشکل مواجه شدم یکی این که نتونستم اون کلید های فیزیکی رو تبدیل به دکمه های ریموت ir کنم . کد با کلید های فیزیکی رو در پایین قرار میدم . ممنون میشم اگر کمک بفرمایید که بتونم اون کلید ها رو با دکمه های ریموت جایگزین کنم . کدهای هکس دکمه های ریموت رو هم دارم .
    و یکی دیگه هم آیا از اون جایی که این پتانسیومتر های دیجیتال 10 پله دارن میشه یه سون سگمنت دارم وصل کنم به دستگاه و از یک تا 100 ولوم رو نشون بده؟ اگر میشه ممنون میشم تو کد نویسی اون هم کمک کنید .
    اینم دیتاشیت سون سگمنتمه

    ببخشید توی کد نویسی تخصصی ندارم فقط دست و پا شکسته یه چیزایی از بقیه پروژه ها یاد گرفتم و در حال یادگیری هستم .
    اینم کد پتانسومتر و کلید فیزیکی

    [FONT=Yekan][code][/code][/FONT][code][/code]
    [code]


    #include <X9C.h> // X9C pot library
    #include <Bounce2.h> // button debounce library


    #define UD 10 // pot up/down mode pin
    #define INC 11 // pot increment pin
    #define CS 12 // pot chip select pin
    #define buttonPotMin 3 // button to set pot to min point
    #define buttonPotMid 4 // button to set pot to mid point
    #define buttonPotMax 5 // button to set pot to max point
    #define buttonPotUp10 6 // button to inc pot by 10
    #define buttonPotDn10 7 // button to dec pot by 10
    #define buttonPotUp1 8 // button to inc pot by 1
    #define buttonPotDn1 9 // button to dec pot by 1


    // X9C wiring: pin 3[High Terminal] -- R1 -- pin 5[Wiper] -- R2 -- pin 6[Low Terminal]


    // The "X9C_UP" direction refers to the amount of resistance being created between the wiper and the "High" terminal
    // rather than the position of the wiper itself moving up toward the high terminal
    // (which would reduce resistance from wiper to High).
    // i.e. setPot(70, false) will set the resistance between the X9C device pins 5 and 3 to 70% of maximum resistance
    // where R1 = 70% of max, R2 = 30% of max


    const int debounceInterval = 10; // debounce time (ms) for button readings


    X9C pot; // instantiate a pot controller
    Bounce buttonPotMinDB = Bounce(); // instantiate a bounce object for each button
    Bounce buttonPotMidDB = Bounce();
    Bounce buttonPotMaxDB = Bounce();
    Bounce buttonPotUp10DB = Bounce();
    Bounce buttonPotDn10DB = Bounce();
    Bounce buttonPotUp1DB = Bounce();
    Bounce buttonPotDn1DB = Bounce();




    void setup() {

    pot.begin(CS, INC, UD);


    pinMode(buttonPotMin, INPUT_PULLUP);
    pinMode(buttonPotMid, INPUT_PULLUP);
    pinMode(buttonPotMax, INPUT_PULLUP);
    pinMode(buttonPotUp10, INPUT_PULLUP);
    pinMode(buttonPotDn10, INPUT_PULLUP);
    pinMode(buttonPotUp1, INPUT_PULLUP);
    pinMode(buttonPotDn1, INPUT_PULLUP);


    // attach buttons to debouncers
    buttonPotMinDB.attach(buttonPotMin);
    buttonPotMinDB.interval(debounceInterval); // interval in ms


    buttonPotMidDB.attach(buttonPotMid);
    buttonPotMidDB.interval(debounceInterval); // interval in ms


    buttonPotMaxDB.attach(buttonPotMax);
    buttonPotMaxDB.interval(debounceInterval); // interval in ms


    buttonPotUp10DB.attach(buttonPotUp10);
    buttonPotUp10DB.interval(debounceInterval); // interval in ms


    buttonPotDn10DB.attach(buttonPotDn10);
    buttonPotDn10DB.interval(debounceInterval); // interval in ms


    buttonPotUp1DB.attach(buttonPotUp1);
    buttonPotUp1DB.interval(debounceInterval); // interval in ms


    buttonPotDn1DB.attach(buttonPotDn1);
    buttonPotDn1DB.interval(debounceInterval); // interval in ms


    }


    void loop() {


    // update the Bounce instances
    buttonPotMinDB.update();
    buttonPotMidDB.update();
    buttonPotMaxDB.update();
    buttonPotUp10DB.update();
    buttonPotDn10DB.update();
    buttonPotUp1DB.update();
    buttonPotDn1DB.update();


    // change potentiometer setting if required based on button presses,
    // storing the setting in the chip if "true" is passed to the pot controller


    if ( buttonPotMinDB.fell()) {
    pot.setPotMin(false); // set pot wiper to 0 resistance (pot will have wiper resistance per datasheet)
    }


    if ( buttonPotMidDB.fell()) {
    pot.setPot(49, false); // set pot wiper to about half way (between 0 and 99)
    }


    if ( buttonPotMaxDB.fell()) {
    pot.setPotMax(false); // set pot wiper to full resistance
    }


    if ( buttonPotUp10DB.fell()) {
    pot.trimPot(10, X9C_UP, true); // move pot wiper 10 positions up ***AND STORE SETTING IN X9C CHIP***
    }


    if ( buttonPotDn10DB.fell()) {
    pot.trimPot(10, X9C_DOWN, false); // move pot wiper 10 positions down
    }


    if ( buttonPotUp1DB.fell()) {
    pot.trimPot(1, X9C_UP, false); // move pot wiper 1 position up
    }


    if ( buttonPotDn1DB.fell()) {
    pot.trimPot(1, X9C_DOWN, true); // move pot wiper 1 position down


    }
    }
    [LEFT][FONT=Yekan][/FONT][/LEFT][/code][LEFT][FONT=Yekan][/FONT][/LEFT]


    جدیدترین ویرایش توسط Ro.alijani; ۰۰:۵۶ ۱۴۰۰/۰۲/۲۵.
لطفا صبر کنید...
X