Kód: Vybrať všetko
#include <Wire.h>
const int Volup = 2; // the pin that the pushbutton is attached to
const int Voldown = 3;
// Variables will change:
int Vol = 50; // counter for the number of button presses
int VolupState = 0; // current state of the button
int lastVolupState = 0; // previous state of the button
int VoldownState = 0;
int lastVoldownState = 0;
int E = 227;
int D = 210;
void setup() {
// initialize the buttons pin as a input:
pinMode(Volup, INPUT);
pinMode(Voldown, INPUT);
Wire.begin();
Serial.begin(9600);
Wire.beginTransmission(0x44);
Wire.write(0xC0);
Wire.write(D);
Wire.write(E);
Wire.endTransmission();
Serial.println("HELLO");
Serial.println("5.1 READY");
Serial.println("Volume: 50");
}
void loop() {
// read the pushbutton input pin:
VolupState = digitalRead(Volup);
VoldownState = digitalRead(Voldown);
if ((E == 232) && (VolupState == HIGH) && (D != 215))
{
E==223;
D++;
}
else if ((E == 224) && (VoldownState == HIGH) && (D != 208))
{
E=233;
D--;
}
// compare the buttonState to its previous state
if (VolupState != lastVolupState) {
// if the state has changed, increment the counter
if ((VolupState == HIGH) && (D + E < 447 )) {
E++;
Vol--;
Serial.print("Volume: ");
Serial.println(Vol);
Wire.beginTransmission(0x44);
Wire.write(0xC0);
Wire.write(D);
Wire.write(E);
Wire.endTransmission();
}
else if ((VolupState == HIGH) && (D + E == 447)) {
Serial.println("Volume:MIN");
}
else{}
}
// compare the buttonState to its previous state
if (VoldownState != lastVoldownState) {
// if the state has changed, increment the counter
if ((VoldownState == HIGH) && (D + E > 432 )) {
E--;
Vol++;
Serial.print("Volume: ");
Serial.println(Vol);
Wire.beginTransmission(0x44);
Wire.write(0xC0);
Wire.write(D);
Wire.write(E);
Wire.endTransmission();
}
else if ((VoldownState == HIGH) && (D+E == 432)) {
Serial.println("Volume:MAX");
}
else{}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastVolupState = VolupState;
lastVoldownState = VoldownState;
}
"HELLO"
"5.1 READY"
"Volume: 50"
(mne vypíše aj volume 51, volume 52, volume 51 ale nerobil mi to s týmto programom... zrejme som poslal veľa dát)
dalej su 2 tlačidlá s pullup rezistormi na pinoch D2 a D3
maju funkciu pridávania a uberania hlasitosti, D2 uberá hlas a D3 pridáva hlas.
Je tam nastavený limit do 71 vtedy má vypísať MAX a pri 0 ma napísať MIN.
hovorím fungovalo mi to ale teraz blbne v pohode si ide keď pridávam až do nekonečna, nereaguje na žiadne ifká a pri spustení hneď začne vypisovať bludy...
mam to skontrolované jak programovo tak hardwarovo , všetko premerané preskúšané, akurat nemam dalšie arduino takže si neviem overiť či som skutočne neodpiekol ten convertor alebo niečo, budem rád ak mi niekto ten kód skúsi