diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:08:27 +0200 |
| commit | c9b6b9a5ca082fe7c1b6f58d7713f785a9eb6a5c (patch) | |
| tree | 3e4f42f93c7ae89a364e4d51fff6e5cec4e55fa9 /rushs/tinyprintf/traffic_lights/traffic_lights.c | |
add: graphs et rushs
Diffstat (limited to 'rushs/tinyprintf/traffic_lights/traffic_lights.c')
| -rw-r--r-- | rushs/tinyprintf/traffic_lights/traffic_lights.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/rushs/tinyprintf/traffic_lights/traffic_lights.c b/rushs/tinyprintf/traffic_lights/traffic_lights.c new file mode 100644 index 0000000..76ea94f --- /dev/null +++ b/rushs/tinyprintf/traffic_lights/traffic_lights.c @@ -0,0 +1,38 @@ +#include "traffic_lights.h" + +void init(unsigned char *lights) +{ + *lights <<= 4; +} + +void turn_on(unsigned char *lights, unsigned char light_num) +{ + *lights |= 1 << (light_num - 1); +} + +void turn_off(unsigned char *lights, unsigned char light_num) +{ + *lights &= ~(1 << (light_num - 1)); +} + +void next_step(unsigned char *lights) +{ + *lights <<= 1; + *lights += *lights >> 4; +} + +void reverse(unsigned char *lights) +{ + *lights = ~*lights; +} + +void swap(unsigned char *lights_1, unsigned char *lights_2) +{ + if (lights_1 == lights_2) + { + return; + } + *lights_1 = *lights_2 ^ *lights_1; + *lights_2 = *lights_1 ^ *lights_2; + *lights_1 = *lights_2 ^ *lights_1; +} |
