From 7bc6cdea7809b4a8c7f39442944e87fb84c4a0e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B8vbr=C3=B8tte=20Olsen?= Date: Mon, 8 May 2017 11:27:54 +0200 Subject: [PATCH] Rotate function This is so stupid, but we felt pretty clever making it. Pls no haet --- School/vg2/borg/borg.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/School/vg2/borg/borg.h b/School/vg2/borg/borg.h index b881864..1b204b4 100644 --- a/School/vg2/borg/borg.h +++ b/School/vg2/borg/borg.h @@ -3,6 +3,7 @@ #include "Arduino.h" #include +#include struct LEDSelect { byte side; @@ -55,6 +56,8 @@ void getNeighborLED(LEDSelect* origin, byte origin_dir, LEDSelect* Result); void getRotNeighborLED(LEDSelect* origin, byte rot, LEDSelect* Result); // void translate(LEDSelect src, LEDSelect dst, CRGB* leds); +// Rotates a side, in given direction, 0 - Clockwise, 1 - Anticlockwise +void rotate(byte side, bool dir, byte n, CRGB* leds); void initMap(void) { @@ -352,6 +355,21 @@ void translate(LEDSelect src, LEDSelect dst, CRGB* leds){ leds[decodeLED(dst)] = leds[decodeLED(src)]; } +void rotate(byte side, bool direction, byte n, CRGB* leds) +{ + byte cyclus[8]; = {0, 3, 6, 7, 8, 5, 2, 1}; + for (byte i = 0; i < n; i++) + { + CRGB Saved = leds[cyclus[7 * direction]]; + for(byte j = 8; j > 0; j--) { + leds[cyclus[j - (8 * !direction)]] = + leds[cyclus[j - (8 * !direction) + (1 * -direction)]]; + } + leds[cyclus[7 - (4 * direction)]] = Saved; + } + +} + bool setColor(LEDSelect selection, CRGB color, CRGB* leds) { if (selection.side == 255) {