Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define R 9
- #define G 10
- #define B 11
- #define B1 4
- #define B2 5
- #define POT A0
- int s0 = 0;
- int s1 = 1;
- int c[3] = {0, 0, 0};
- class Color {
- public:
- int r, g, b;
- void update(int r, int g, int b);
- Color(int r, int g, int b);
- };
- class Ledstring {
- public:
- int r_pin, g_pin, b_pin; //attached pin
- int r, g, b; //colors
- int start = 0;
- int in = 0;
- Ledstring(int, int, int);
- void off();
- //ALERT:these functions just load the value in the buffer
- //call the show function to show off the buffer values
- void write(int, int, int);
- void write(Color*);
- void show();
- void init();
- //these are premade animations (very simple ones)
- void naivefade(int);
- void blink();//blink uses the buffer color
- void plasma();
- void fixed();
- void autome();
- //some utilities
- void b2C(Color*);
- };
- Color black(0, 0, 0);
- Color white(255, 255, 255);
- Ledstring strip(9, 10, 11);
- void setup() {
- strip.init();
- pinMode(B1, INPUT_PULLUP);
- pinMode(B2, INPUT_PULLUP);
- }
- void loop() {
- strip.autome();
- if (digitalRead(B1) == LOW) {
- while (digitalRead(B1) == LOW) {}
- if (s0 < 4) {
- s0++;
- }
- else s0 = 0;
- }
- if (digitalRead(B2) == LOW) {
- while (digitalRead(B2) == LOW) {}
- if (s1 < 2) {
- s1++;
- }
- else s1 = 0;
- c[s1] = map(analogRead(POT), 0, 1024, 0, 255);
- }
- }
- void Color::update(int r, int g, int b) {
- this->r = r;
- this->g = g;
- this->b = b;
- }
- Color::Color(int r, int g, int b) {
- this->update(r, g, b);
- }
- Ledstring::Ledstring(int r, int g, int b) {
- this->r_pin = r;
- this->g_pin = g;
- this->b_pin = b;
- }
- void Ledstring::init() {
- pinMode(this->r_pin, OUTPUT);
- pinMode(this->g_pin, OUTPUT);
- pinMode(this->b_pin, OUTPUT);
- }
- void Ledstring::write(int r, int g, int b) {
- this->r = r;
- this->g = g;
- this->b = b;
- }
- void Ledstring::write(Color* col) {
- this->r = col->r;
- this->g = col->g;
- this->b = col->b;
- }
- void Ledstring::show() {
- analogWrite(this->r_pin, this->r);
- analogWrite(this->g_pin, this->g);
- analogWrite(this->b_pin, this->b);
- }
- void Ledstring::off() {
- this->write(&black);
- this->show();
- }
- void Ledstring::fixed() {
- this->show();
- }
- void Ledstring::blink() {
- if (this->start < millis()) {
- if (this->in) {
- this->off();
- this->in = 0;
- }
- else {
- this->write(c[0], c[1], c[2]);
- this->show();
- this->in = 1;
- }
- this->start = millis() + 300;
- }
- }
- void Ledstring::autome() {
- switch (s0) {
- case 0:
- this->fixed();
- break;
- case 1:
- //plasma();
- break;
- case 2:
- this->blink();
- break;
- }
- }
- void Ledstring::b2C(Color * col) {
- col->r = this->r;
- col->g = this->g;
- col->n = this->b;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement