//* Lack of enumeration AND HAL simulation for the sake of testing *

#include <stdint.h> // for uintN_t /* Simple LED + button HAL simulator -- headers */ #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> // for printf/scanf #include <conio.h> // for _kbdhit, _getch - all non-standard C goodies void LED1(uint8_t v); void LED2(uint8_t v); void LED3(uint8_t v); uint8_t UButtton(); #define mode_max 3 int main() { uint8_t mode = 0; uint8_t last = 0; while (1) { switch (mode) { case 0: LED1(1); LED2(0); LED3(0); break; case 1: LED1(0); LED2(1); LED3(0); break; case 2: LED1(0); LED2(0); LED3(1); break; } uint8_t current = UButtton(); if (current != last) { last = current; if (current) { mode++; if (mode >= mode_max) mode = 0; } } } return 0; } /* Simple LED + button HAL simulator -- implementation */ uint8_t lr = 0, lg = 0, lb = 0; void showLEDs() { if (lr) printf("R"); else printf("r"); if (lg) printf("G"); else printf("g"); if (lb) printf("B"); else printf("b"); printf("\r"); } void LED1(uint8_t v) { lr = v; showLEDs(); } void LED2(uint8_t v) { lg = v; showLEDs(); } void LED3(uint8_t v) { lb = v; showLEDs(); } uint8_t UButtton() { if (_kbhit()) { _getch(); return(1); } else return(0); }