int pin_cervena = 5;
int pin_zelena = 4;
int pin_modra = 3;
int pin_tlacidlo = 6;
int pin_potenciometer = A0;
bool stav_tlacidla;
int potenciometer_raw;
int potenciometer_map;
int pocitadlo;
int a,b,c,d,e;
void setup() {
// put your setup code here, to run once:
pinMode(pin_zelena, OUTPUT);
pinMode(pin_modra, OUTPUT);
pinMode(pin_cervena, OUTPUT);
pinMode(pin_tlacidlo, INPUT);
pinMode(pin_potenciometer, INPUT);
pocitadlo=0;
Serial.begin(9600);
Serial.println("Kalkulator 3000");
delay(3000);
}
void loop() {
// put your main code here, to run repeatedly:
stav_tlacidla = digitalRead(pin_tlacidlo);
potenciometer_raw=analogRead(A0);
potenciometer_map=map(potenciometer_raw,0,1023,1,9);
if(stav_tlacidla==1){
pocitadlo++;
delay(250);
}
if(pocitadlo == 0){
Serial.print("vyber cislo 1: ");
Serial.println(potenciometer_map);
a=potenciometer_map;
}
if(pocitadlo == 1){
Serial.print("vyber cislo 2: ");
Serial.println(potenciometer_map);
b=potenciometer_map;
}
if(pocitadlo == 2){
Serial.print("vyber cislo 3: ");
Serial.println(potenciometer_map);
c=potenciometer_map;
}
if(pocitadlo == 3){
Serial.print("vyber cislo 4: ");
Serial.println(potenciometer_map);
d=potenciometer_map;
}
if(pocitadlo == 4){
Serial.print("Cislo 1: ");
Serial.print(a);
Serial.print(" Cislo 2: ");
Serial.print(b);
Serial.print(" Cislo 3: ");
Serial.print(c);
Serial.print(" Cislo 4: ");
Serial.print(d);
delay(3000);
Serial.print("Pocitam...");
delay(1000);
e=a*b*c*d;
Serial.print("vysledok je");
Serial.print(e);
Serial.print(".");
pocitadlo++;
}
if (pocitadlo ==5){
if(0<e && e<2187){
digitalWrite(pin_cervena, HIGH);
digitalWrite(pin_zelena, LOW);
digitalWrite(pin_modra, LOW);
}
if(2187<e && e<4374){
digitalWrite(pin_cervena, HIGH);
digitalWrite(pin_zelena, HIGH);
digitalWrite(pin_modra, LOW);
}
if(4374<e && e<6562){
digitalWrite(pin_cervena, HIGH);
digitalWrite(pin_zelena, HIGH);
digitalWrite(pin_modra, HIGH);
}
delay(10000);
digitalWrite(pin_cervena, LOW);
digitalWrite(pin_zelena, LOW);
digitalWrite(pin_modra, LOW);
pocitadlo=0;
}
}
Please use something like google translate to translate to English.
Please edit your post, select all code and click the <CODE>
button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and the forum software will display it correctly; see also How to get the best out of this forum.
Please describe the problem that you are experiencing.
I moved your topic to a more appropriate forum category @reklamy.
In the future, please take the time to pick the forum category that best suits the subject of your question. There is an "About the _____ category" topic at the top of each category that explains its purpose.
Thanks in advance for your cooperation.
Is this topic connected to your other topic about potentiometer?
Please note that opening a more than one topic about the same subject is a violation of the forum rules.
"Calculator using potentiometer and button"
int pin_cervena = 5; // red
int pin_zelena = 4; // green
int pin_modra = 3; // blue
int pin_tlacidlo = 6; // button
int pin_potenciometer = A0;
bool stav_tlacidla; // status button
int potenciometer_raw;
int potenciometer_map;
int pocitadlo; // abacus :)
int a, b, c, d, e;
void setup() {
// put your setup code here, to run once:
pinMode(pin_zelena, OUTPUT);
pinMode(pin_modra, OUTPUT);
pinMode(pin_cervena, OUTPUT);
pinMode(pin_tlacidlo, INPUT);
pinMode(pin_potenciometer, INPUT);
pocitadlo = 0;
Serial.begin(9600);
Serial.println("Kalkulator 3000 (abucus 3000)");
delay(3000);
}
void loop() {
// put your main code here, to run repeatedly:
stav_tlacidla = digitalRead(pin_tlacidlo);
potenciometer_raw = analogRead(A0);
potenciometer_map = map(potenciometer_raw, 0, 1023, 1, 9);
if (stav_tlacidla == 1) {
pocitadlo++;
delay(250);
}
if (pocitadlo == 0) {
Serial.print("vyber cislo (picking number) 1: "); // pick number 1
Serial.println(potenciometer_map);
a = potenciometer_map;
}
if (pocitadlo == 1) {
Serial.print("vyber cislo (picking number) 2: ");
Serial.println(potenciometer_map);
b = potenciometer_map;
}
if (pocitadlo == 2) {
Serial.print("vyber cislo (picking number) 3: ");
Serial.println(potenciometer_map);
c = potenciometer_map;
}
if (pocitadlo == 3) {
Serial.print("vyber cislo (picking number) 4: ");
Serial.println(potenciometer_map);
d = potenciometer_map;
}
if (pocitadlo == 4) {
Serial.print("Cislo (number) 1: ");
Serial.print(a);
Serial.print(" Cislo (number) 2: ");
Serial.print(b);
Serial.print(" Cislo (number) 3: ");
Serial.print(c);
Serial.print(" Cislo (number) 4: ");
Serial.print(d);
delay(3000);
Serial.print("\nPocitam... (counting) ");
delay(1000);
e = a * b * c * d;
Serial.print("vysledok je (outcome) "); // outcome
Serial.print(e);
Serial.print(".");
pocitadlo++;
}
if (pocitadlo == 5) {
if (0 < e && e < 2187) {
digitalWrite(pin_cervena, HIGH);
digitalWrite(pin_zelena, LOW);
digitalWrite(pin_modra, LOW);
}
if (2187 < e && e < 4374) {
digitalWrite(pin_cervena, HIGH);
digitalWrite(pin_zelena, HIGH);
digitalWrite(pin_modra, LOW);
}
if (4374 < e && e < 6562) {
digitalWrite(pin_cervena, HIGH);
digitalWrite(pin_zelena, HIGH);
digitalWrite(pin_modra, HIGH);
}
delay(10000);
digitalWrite(pin_cervena, LOW);
digitalWrite(pin_zelena, LOW);
digitalWrite(pin_modra, LOW);
pocitadlo = 0;
}
}
diagram.json for wokwi.com
{
"version": 1,
"author": "Anonymous maker",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-nano", "id": "nano", "top": -72, "left": -0.5, "attrs": {} },
{
"type": "wokwi-led",
"id": "led1",
"top": -166.8,
"left": 90.6,
"attrs": { "color": "red", "flip": "1" }
},
{
"type": "wokwi-led",
"id": "led2",
"top": -166.8,
"left": 71.4,
"attrs": { "color": "red", "flip": "1" }
},
{
"type": "wokwi-led",
"id": "led3",
"top": -166.8,
"left": 52.2,
"attrs": { "color": "red", "flip": "1" }
},
{
"type": "wokwi-pushbutton",
"id": "btn1",
"top": -118.6,
"left": 124.8,
"attrs": { "color": "green" }
},
{ "type": "wokwi-potentiometer", "id": "pot1", "top": -145.3, "left": 211, "attrs": {} }
],
"connections": [
[ "nano:GND.2", "led1:C", "black", [ "v0" ] ],
[ "nano:GND.2", "led2:C", "black", [ "v0" ] ],
[ "nano:GND.2", "led3:C", "black", [ "v0" ] ],
[ "led1:A", "nano:3", "green", [ "v0" ] ],
[ "led2:A", "nano:4", "green", [ "v9.6", "h9.6" ] ],
[ "led3:A", "nano:5", "green", [ "v9.6", "h19.2" ] ],
[ "nano:GND.2", "btn1:2.l", "black", [ "v0" ] ],
[ "nano:6", "btn1:1.l", "green", [ "v0" ] ],
[ "pot1:GND", "nano:GND.1", "black", [ "v76.8", "h-96" ] ],
[ "pot1:SIG", "nano:A0", "green", [ "v86.4", "h-182.8" ] ],
[ "pot1:VCC", "nano:5V", "red", [ "v96", "h-125.6" ] ]
],
"dependencies": {}
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.