Created
April 18, 2020 21:51
-
-
Save paulwinex/67c74de747a0bec97fcc142f5e20feec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <TFT_eSPI.h> | |
#define PIXELPIN 5 | |
#define NUMPIXELS 5 | |
#define pixlux 20 | |
#define BUTTON_1 35 | |
#define BUTTON_2 0 | |
#define SW 135 | |
#define SH 240 | |
TFT_eSPI tft = TFT_eSPI(SW, SH); | |
float col[3]; | |
void setup() { | |
tft.begin(); | |
tft.setRotation(0); | |
tft.fillScreen(TFT_BLACK); | |
tft.setTextColor(0x5E85); | |
tft.setTextSize(3); | |
pinMode(BUTTON_1, INPUT_PULLUP); | |
pinMode(BUTTON_2, INPUT_PULLUP); | |
attachInterrupt(digitalPinToInterrupt(BUTTON_1),reset, FALLING); | |
attachInterrupt(digitalPinToInterrupt(BUTTON_2),reset, FALLING); | |
} | |
float fract(float x) { return x - int(x); } | |
float mix(float a, float b, float t) { return a + (b - a) * t; } | |
float step(float e, float x) { return x < e ? 0.0 : 1.0; } | |
float* hsv2rgb(float h, float s, float b, float* rgb) { | |
rgb[0] = b * mix(1.0, constrain(abs(fract(h + 1.0) * 6.0 - 3.0) - 1.0, 0.0, 1.0), s); | |
rgb[1] = b * mix(1.0, constrain(abs(fract(h + 0.6666666) * 6.0 - 3.0) - 1.0, 0.0, 1.0), s); | |
rgb[2] = b * mix(1.0, constrain(abs(fract(h + 0.3333333) * 6.0 - 3.0) - 1.0, 0.0, 1.0), s); | |
return rgb; | |
} | |
void reset(){ | |
} | |
float ramp_step = SH/360.0; | |
void loop() { | |
for (int i=0; i++; i<SH){ | |
tft.drawLine(0, i, SW, i, hsv2rgb(ramp_step*i, 1.0, 1.0, col)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment