bool tlacidlo;
int potenciometer;
int hodnota;
int pocitadlo;
void setup() {
// put your setup code here, to run once:
pinMode(6, INPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
pinMode(A0, INPUT);
pocitadlo = 0;
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
tlacidlo = digitalRead(6);
//Serial.println(tlacidlo);
potenciometer = analogRead(A0);
//Serial.println(potenciometer);
hodnota = map(potenciometer, 0, 1023, 1,4);
//Serial.println(hodnota);
Serial.println(hodnota);
if(tlacidlo == 1)
{
pocitadlo++;
delay(250);
}
if(pocitadlo == 1)
{
if(hodnota == 1)
{
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
}
if(hodnota == 2)
{
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
}
if(hodnota == 3)
{
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
}
if(hodnota == 4)
{
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(3, HIGH);
digitalWrite(2, HIGH);
}
}
if(pocitadlo == 0)
{
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
}
if(pocitadlo > 1)
{
pocitadlo = 0;
}
}
Welcome to the Forum! Read the forum guidelines to see how to properly ask a question and some good information on making a good post.
Use English to post in main forum category.
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.
"LED illumination through potentiometer"
It works! Dial the potentiometer (1 - 4), press the button, "pot" LEDs light.
bool tlacidlo; // button
int potenciometer;
int hodnota; // value
int pocitadlo; // counter
void setup() {
// put your setup code here, to run once:
pinMode(6, INPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
pinMode(2, OUTPUT);
pinMode(A0, INPUT);
pocitadlo = 0;
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
tlacidlo = digitalRead(6);
//Serial.println(tlacidlo);
potenciometer = analogRead(A0);
//Serial.println(potenciometer);
hodnota = map(potenciometer, 0, 1023, 1, 4);
//Serial.println(hodnota);
Serial.print("hodnota/value = "); // value
Serial.println(hodnota); // value
if (tlacidlo == 1) {
pocitadlo++;
delay(250);
}
if (pocitadlo == 1) {
if (hodnota == 1) {
digitalWrite(5, HIGH);
digitalWrite(4, LOW);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
}
if (hodnota == 2) {
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
}
if (hodnota == 3) {
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
}
if (hodnota == 4) {
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
digitalWrite(3, HIGH);
digitalWrite(2, HIGH);
}
}
if (pocitadlo == 0) {
digitalWrite(5, LOW);
digitalWrite(4, LOW);
digitalWrite(3, LOW);
digitalWrite(2, LOW);
}
if (pocitadlo > 1) {
pocitadlo = 0;
}
delay(250);
}
diagram.json for wokwi.com
{
"version": 1,
"author": "Anonymous maker",
"editor": "wokwi",
"parts": [
{ "type": "wokwi-arduino-nano", "id": "nano", "top": -4.8, "left": 9.1, "attrs": {} },
{
"type": "wokwi-pushbutton",
"id": "btn1",
"top": -61,
"left": 172.8,
"attrs": { "color": "green" }
},
{ "type": "wokwi-led", "id": "led1", "top": -90, "left": 99.8, "attrs": { "color": "red" } },
{ "type": "wokwi-led", "id": "led2", "top": -90, "left": 80.6, "attrs": { "color": "red" } },
{ "type": "wokwi-led", "id": "led3", "top": -90, "left": 61.4, "attrs": { "color": "red" } },
{ "type": "wokwi-led", "id": "led4", "top": -90, "left": 42.2, "attrs": { "color": "red" } },
{ "type": "wokwi-potentiometer", "id": "pot1", "top": -10.9, "left": 182.2, "attrs": {} }
],
"connections": [
[ "nano:GND.2", "btn1:2.l", "black", [ "v0" ] ],
[ "nano:6", "btn1:1.l", "green", [ "v0" ] ],
[ "nano:2", "led1:A", "green", [ "v0" ] ],
[ "nano:3", "led2:A", "green", [ "v0" ] ],
[ "nano:4", "led3:A", "green", [ "v0" ] ],
[ "nano:5", "led4:A", "green", [ "v0" ] ],
[ "nano:GND.2", "led4:C", "black", [ "v-38.4", "h-77.2" ] ],
[ "nano:GND.2", "led3:C", "black", [ "v-38.4", "h-58" ] ],
[ "nano:GND.2", "led2:C", "black", [ "v-38.4", "h-38.8" ] ],
[ "nano:GND.2", "led1:C", "black", [ "v-38.4", "h-19.6" ] ],
[ "pot1:GND", "nano:GND.1", "black", [ "v19.2", "h-57.6" ] ],
[ "pot1:VCC", "nano:5V", "red", [ "v28.8", "h-96.8" ] ],
[ "pot1:SIG", "nano:A0", "green", [ "v9.6", "h-163.6" ] ]
],
"dependencies": {}
}
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.