From 1315fc990ed5acbda72116ad91c8d955100f5eb3 Mon Sep 17 00:00:00 2001 From: KP9lKk Date: Fri, 28 Mar 2025 13:20:44 +0300 Subject: [PATCH] print number --- diagram.json | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- src/main.cpp | 29 +++++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/diagram.json b/diagram.json index 10e8601..7b6c8e5 100644 --- a/diagram.json +++ b/diagram.json @@ -13,7 +13,34 @@ "left": 258.65, "rotate": 90, "attrs": { "value": "250" } - } + }, + { + "type": "wokwi-resistor", + "id": "r2", + "top": 72, + "left": 287.45, + "rotate": 90, + "attrs": { "value": "250" } + }, + { + "type": "wokwi-resistor", + "id": "r3", + "top": 72, + "left": 316.25, + "rotate": 90, + "attrs": { "value": "250" } + }, + { + "type": "wokwi-resistor", + "id": "r4", + "top": 72, + "left": 345.05, + "rotate": 90, + "attrs": { "value": "250" } + }, + { "type": "wokwi-led", "id": "led2", "top": 102, "left": 291.8, "attrs": { "color": "red" } }, + { "type": "wokwi-led", "id": "led3", "top": 102, "left": 320.6, "attrs": { "color": "red" } }, + { "type": "wokwi-led", "id": "led4", "top": 102, "left": 349.4, "attrs": { "color": "red" } } ], "connections": [ [ "uno:GND.1", "bb1:tn.1", "black", [ "v0" ] ], @@ -22,8 +49,29 @@ [ "uno:13", "bb1:6t.a", "green", [ "v0" ] ], [ "r1:1", "bb1:6t.b", "", [ "$bb" ] ], [ "r1:2", "bb1:6b.f", "", [ "$bb" ] ], + [ "r2:1", "bb1:9t.b", "", [ "$bb" ] ], + [ "r2:2", "bb1:9b.f", "", [ "$bb" ] ], + [ "r3:1", "bb1:12t.b", "", [ "$bb" ] ], + [ "r3:2", "bb1:12b.f", "", [ "$bb" ] ], + [ "r4:1", "bb1:15t.b", "", [ "$bb" ] ], + [ "r4:2", "bb1:15b.f", "", [ "$bb" ] ], + [ "bb1:tn.5", "bb1:8t.a", "green", [ "v0" ] ], + [ "bb1:tn.8", "bb1:11t.a", "green", [ "v0" ] ], + [ "bb1:tn.10", "bb1:14t.a", "green", [ "v0" ] ], [ "led1:A", "bb1:6b.j", "", [ "$bb" ] ], - [ "led1:C", "bb1:5b.j", "", [ "$bb" ] ] + [ "led1:C", "bb1:5b.j", "", [ "$bb" ] ], + [ "led2:A", "bb1:9b.j", "", [ "$bb" ] ], + [ "led2:C", "bb1:8b.j", "", [ "$bb" ] ], + [ "led3:A", "bb1:12b.j", "", [ "$bb" ] ], + [ "led3:C", "bb1:11b.j", "", [ "$bb" ] ], + [ "led4:A", "bb1:15b.j", "", [ "$bb" ] ], + [ "led4:C", "bb1:14b.j", "", [ "$bb" ] ], + [ "uno:12", "bb1:9t.a", "green", [ "v0" ] ], + [ "uno:11", "bb1:12t.a", "green", [ "v0" ] ], + [ "uno:10", "bb1:15t.a", "green", [ "v0" ] ], + [ "bb1:8t.e", "bb1:8b.f", "green", [ "v0" ] ], + [ "bb1:11t.e", "bb1:11b.f", "green", [ "v0" ] ], + [ "bb1:14t.e", "bb1:14b.f", "green", [ "v0" ] ] ], "dependencies": {} } \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 6cdb7c2..2d2000c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,34 @@ #include -int pin13 = 13; +constexpr int size = 4; +int pins[size] = {13, 12, 11, 10}; +int digits[size] = {0, 0, 0, 0}; + + +void toBinary(int number){ + for(size_t i = (size - 1); i != size_t(-1); i--){ + digits[i] = number % 2; + Serial.println(number % 2); + number /= 2; + } +} + void setup() { - pinMode(pin13, OUTPUT); + for(const int& pin : pins){ + pinMode(pin, OUTPUT); + } } void loop() { delay(3000); - digitalWrite(pin13, HIGH); + toBinary(15); + for(size_t i = 0; i < size; i++ ){ + digitalWrite(pins[i], digits[i]); + } delay(3000); - digitalWrite(pin13, LOW); } + + + + +