Hello,
I want to make 5V, 9V, 12V charger for powerbank supporting
Qualcomm Quick Charge 3.0 A.
I used button for switching between 5V, 9V, 12V,
single press = 5V
double press = 9V
triple press = 12V
I tried use this code, but I'm beginer and I don't know how to make
working code.
Please help me with the code.
#include <QC3Control.h>
QC3Control quickCharge(8, 7);
int Button = 10;
int qcdelay = 0;
int qc = 0;
int curbut;
int lastbut = 0;
void setup() {
pinMode(Button, INPUT);
}
void loop() {
curbut = digitalRead(Button);
qcdelay = qcdelay + 1;
if (curbut != lastbut){
if (curbut == HIGH){
qc = qc + 1;
qcdelay = 0;
}
}
if (qcdelay >= 200){
if (qc == 1){
quickCharge.set5V();
qc = 0;
}
if (qc == 2){
quickCharge.set9V();
qc = 0;
}
if (qc == 3){
quickCharge.set12V();
qc = 0;
}
qcdelay = 0;
}
lastbut = curbut;
delay(1);
}
This way is too complicated for me (I said "I'm beginer"). I now use very easy code where if I press button it switch to 9V, press again for 12V and again for 5V back. It works and i is very easy, but thank you for your help.
ProDigy_Ziege:
This way is too complicated for me (I said "I'm beginer"). I now use very easy code where if I press button it switch to 9V, press again for 12V and again for 5V back. It works and i is very easy, but thank you for your help.
Beginners should start with the blink sketch and not try to complete a graduate project.
But, if you study the code I presented, hopefully you will learn a little more, as I modified your code.
Robin2 is right. You have no way of knowing if you are outputting 5, 9 or 12 volts or which "press" you are on.
Perehama:
Beginners should start with the blink sketch and not try to complete a graduate project.
But, if you study the code I presented, hopefully you will learn a little more, as I modified your code.
Robin2 is right. You have no way of knowing if you are outputting 5, 9 or 12 volts or which "press" you are on.
This isn't a graduate project. It's not even close to what I would call hard, it's literally just one thing.
ProDigy_Ziege:
This way is too complicated for me (I said "I'm beginer"). I now use very easy code where if I press button it switch to 9V, press again for 12V and again for 5V back. It works and i is very easy, but thank you for your help.
I still recommend investigating why your original code didn't work, because that will understand what you did wrong and what you can do differently when you try it next time. And I think I have found a problem.
You have cases set up for single-click, double-click, and triple-click. But what if you quadruple click? If you do 4 or more rapid clicks, you will go outside the range you are expecting, qc will never get reset and nothing will get triggered again unless you happen to click 65,000 more times to roll it back over to 0 and land back into the window. And the odds of that actually happening are quite low.
When you aren't sure about what's happening, print things to Serial. Right after you add 1 to qc, print its value to the Serial monitor so you can see what it's doing. Find some places to print out the value of qcdelay so you can see if it is working as you expect it. Bottom line is to get more information about the internal workings of your code and make sure that every little gear and lever is doing exactly what you expect it to be doing and not going all crazy.