#include <Adafruit_NeoPixel.h>
//https://adafruit.github.io/Adafruit_NeoPixel/html/class_adafruit___neo_pixel.html#ab932cb619cd3420f9e3f269b7401710e
/**
Written by Hamid Attarzadeh
https://freelivenet.com
*/
#define PIN 2 //Output pin
#define POTENTIOMETER_PIN A0
#define MAX_LED 128 //Quantity of LED
uint32_t ledColor;
int ledPos;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(MAX_LED, PIN, NEO_RGB + NEO_KHZ800);
/*
0 1 2 3 4 5 6 7
--------------------------------
0 | 0 1 2 3 4 5 6 7
1 | 15 14 13 12 11 10 9 8
2 | 16 17 18 19 20 21 22 23
3 | 31 30 29 28 27 26 25 24
4 | 32 33 34 35 36 37 38 39
5 | 47 46 45 44 43 42 41 40
6 | 48 49 50 51 52 53 54 55
7 | 63 62 61 60 59 58 57 56
*/
int xy2pos(int x, int y) {
if (y % 2 == 0) {
return (y * 8 + x);
} else {
return (y * 8 + (7 - x));
}
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("0x0 = " + String(xy2pos(0, 0)));
Serial.println("0x1 = " + String(xy2pos(0, 1)));
Serial.println("1x1 = " + String(xy2pos(1, 1)));
Serial.println("1x2 = " + String(xy2pos(1, 2)));
Serial.println("3x3 = " + String(xy2pos(3, 3)));
Serial.println("4x3 = " + String(xy2pos(4, 3)));
drawline(1, 1, 1, 4);
strip.show();
drawRectangle(1, 1, 4, 1);
strip.show();
ledColor = strip.color(100, 200, 250, 20);
}
void loop() {
// put your main code here, to run repeatedly:
}
void drawline(int x1, int y1, int x2, int y2) {
Serial.println("Line from " + String(x1) + "x" + String(y1) + " to " + String(x2) + "x" + String(y2));
for (int x = x1; x <= x2; x++) {
for (int y = y1; y <= y2; y++) {
ledPos = xy2pos(x, y);
strip.setColor(ledPos, ledColor);
Serial.print(String(xy2pos(x, y)) + " , ");
// Serial.println(String(x) + "x" + String(y) + " = " + String(xy2pos(x, y)) + " , ");
}
}
Serial.print("");
Serial.println("-----------------------------");
}
void drawRectangle(int x1, int y1, int x2, int y2) {
drawline(x1, y1, x2, y1);
drawline(x1, y1, x1, y2);
drawline(x2, y1, x2, y2);
drawline(x1, y2, x2, y2);
}