]> kolegite.com Git - vmks.git/commitdiff
Ivan's demonstration projects
authorIvan Stefanov <istefanov@elsys-bg.org>
Wed, 21 Oct 2020 15:51:36 +0000 (18:51 +0300)
committerIvan Stefanov <istefanov@elsys-bg.org>
Wed, 21 Oct 2020 15:51:36 +0000 (18:51 +0300)
П-ВМКС Решения на задачите от занятията за преговор по Програмиране на ВМКС за 12 клас в ТУЕС.

3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose-Schematic.png [new file with mode: 0644]
3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose.ino [new file with mode: 0644]
Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR-Schematic.png [new file with mode: 0644]
Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR.ino [new file with mode: 0644]
Digital_Blink_with_Button/Digital_Blink_with_Button-Schematic.png [new file with mode: 0644]
Digital_Blink_with_Button/Digital_Blink_with_Button.ino [new file with mode: 0644]

diff --git a/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose-Schematic.png b/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose-Schematic.png
new file mode 100644 (file)
index 0000000..472ae2b
Binary files /dev/null and b/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose-Schematic.png differ
diff --git a/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose.ino b/3x3-LED_BTN-Matrix-Transpose/3x3-LED_BTN-Matrix-Transpose.ino
new file mode 100644 (file)
index 0000000..e265976
--- /dev/null
@@ -0,0 +1,85 @@
+#define LED_ROW1 11  // Active HIGH | Inactive LOW
+#define LED_ROW2 10 // Active HIGH | Inactive LOW
+#define LED_ROW3 9  // Active HIGH | Inactive LOW
+#define LED_COL1 8  // Active LOW  | Inactive HIGH
+#define LED_COL2 7  // Active LOW  | Inactive HIGH
+#define LED_COL3 6  // Active LOW  | Inactive HIGH
+
+#define BTN_ROW1 A3 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
+#define BTN_ROW2 A4 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
+#define BTN_ROW3 A5 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
+#define BTN_COL1 A0 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
+#define BTN_COL2 A1 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
+#define BTN_COL3 A2 // Active OUTPUT-LOW | Inactive INPUT - PULLUP
+
+const uint8_t led_col[3] = {LED_COL1, LED_COL2, LED_COL3};
+const uint8_t led_row[3] = {LED_ROW1, LED_ROW2, LED_ROW3};
+
+const uint8_t btn_col[3] = {BTN_COL1, BTN_COL2, BTN_COL3};
+const uint8_t btn_row[3] = {BTN_ROW1, BTN_ROW2, BTN_ROW3};
+
+uint8_t state_1[3][3] =
+{
+  {0, 0, 0},
+  {0, 0, 0},
+  {0, 0, 0}
+};
+
+void setup()
+{
+  int i = 0;
+
+  for (i = 0; i < 3; i++)
+  {
+    pinMode(led_row[i], OUTPUT);
+    digitalWrite(led_row[i], LOW);
+    pinMode(led_col[i], OUTPUT);
+    digitalWrite(led_col[i], HIGH);
+
+    pinMode(btn_row[i], INPUT_PULLUP);
+    pinMode(btn_col[i], INPUT_PULLUP);
+  }
+}
+
+void loop()
+{
+  // Button scan
+  for (byte col = 0; col < 3; col++)
+  {
+    pinMode(btn_col[col], OUTPUT);
+    digitalWrite(btn_col[col], LOW);
+    for (byte row = 0; row < 3; row++)
+    {
+      state_1[row][col] = !digitalRead(btn_row[row]);
+    }
+    pinMode(btn_col[col], INPUT_PULLUP);
+  }
+
+  // Transpose
+  for (int i = 0; i < 3; i++)
+  {
+    for (int j = i + 1; j < 3; j++)
+    {
+      int temp;
+      temp = state_1[i][j];
+      state_1[i][j] = state_1[j][i];
+      state_1[j][i] = temp;
+    }
+  }
+
+  // LED update
+  for (byte col = 0; col < 3; col++)
+  {
+    for (byte row = 0; row < 3; row++)
+    {
+      digitalWrite(led_row[row], state_1[row][col]);
+    }
+    digitalWrite(led_col[col], LOW);
+    delay(5);
+    digitalWrite(led_col[col], HIGH);
+    for (byte row = 0; row < 3; row++)
+    {
+      digitalWrite(led_row[row], LOW);
+    }
+  }
+}
diff --git a/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR-Schematic.png b/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR-Schematic.png
new file mode 100644 (file)
index 0000000..49d7cc0
Binary files /dev/null and b/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR-Schematic.png differ
diff --git a/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR.ino b/Analog_Serial_Send_-_LDR/Analog_Serial_Send_-_LDR.ino
new file mode 100644 (file)
index 0000000..6cb7a7b
--- /dev/null
@@ -0,0 +1,16 @@
+#define LDR A0
+
+uint16_t value = 0;
+
+void setup()
+{
+  pinMode(A0, INPUT);
+  Serial.begin(9600);
+}
+
+void loop()
+{
+  value = analogRead(LDR);
+  Serial.println(value);
+  delay(100);
+}
diff --git a/Digital_Blink_with_Button/Digital_Blink_with_Button-Schematic.png b/Digital_Blink_with_Button/Digital_Blink_with_Button-Schematic.png
new file mode 100644 (file)
index 0000000..e15310c
Binary files /dev/null and b/Digital_Blink_with_Button/Digital_Blink_with_Button-Schematic.png differ
diff --git a/Digital_Blink_with_Button/Digital_Blink_with_Button.ino b/Digital_Blink_with_Button/Digital_Blink_with_Button.ino
new file mode 100644 (file)
index 0000000..e5ef2d4
--- /dev/null
@@ -0,0 +1,32 @@
+#define BTN 2
+#define LED 5
+
+byte stateON = false;
+uint8_t count = 0;
+
+void setup()
+{
+  pinMode(BTN, INPUT);
+  pinMode(LED, OUTPUT);
+}
+
+void loop()
+{
+  if(digitalRead(BTN) == 0)
+  {
+    stateON = true;
+  }
+  
+  if(stateON == true)
+  {
+    digitalWrite(LED, HIGH);
+    delay(500);
+    digitalWrite(LED, LOW);
+    delay(500);
+    count++;
+    if(count >= 5)
+    {
+      stateON = false;
+    }
+  }
+}