#include <Arduino.h>
int counter = 0;
const int segPins[] = {PA4, PA5, PA6, PA7, PA8, PA11, PA12};
// Mapping Common Anode
const uint8_t anode_map[][7] = {
{0,0,0,0,0,0,1}, {1,0,0,1,1,1,1}, {0,0,1,0,0,1,0},
{0,0,0,0,1,1,0}, {1,0,0,1,1,0,0}, {0,1,0,0,1,0,0},
{0,1,0,0,0,0,0}, {0,0,0,1,1,1,1}, {0,0,0,0,0,0,0}, {0,0,0,0,1,0,0}
};
void updateDisplay() {
for (int i = 0; i < 7; i++) {
digitalWrite(segPins[i], anode_map[counter][i]);
}
}
void setup() {
// Setup Segmen
for (int i = 0; i < 7; i++) {
pinMode(segPins[i], OUTPUT);
}
// Guna pin D0 dan D1 (Guna nombor pin fizikal)
pinMode(0, INPUT_PULLUP); // D0 adalah GPIO pin 0
pinMode(1, INPUT_PULLUP); // D1 adalah GPIO pin 1
updateDisplay();
}
void loop() {
// Test Butang A (D0 / Pin 0)
if (digitalRead(0) == LOW) {
delay(150); // Debounce lebih lama sikit
if (counter < 9) {
counter++;
updateDisplay();
}
while(digitalRead(0) == LOW);
}
// Test Butang B (D1 / Pin 1)
if (digitalRead(1) == LOW) {
delay(150);
if (counter > 0) {
counter--;
updateDisplay();
}
while(digitalRead(1) == LOW);
}
}Loading
st-nucleo-c031c6
st-nucleo-c031c6