Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//This is a midified sketch which receives i2c messages and also implements Fast LEd library
//to make an led animation based on messages sent from the touchboard
// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>
// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this
// Created 29 March 2006
// This example code is in the public domain.
#include<Wire.h>
//library for LEDs
#include "FastLED.h"
// How many leds in your strip?
#define NUM_LEDS 18
#define DATA_PIN 3 // defines which digital pin to connect the strip data lead
#define BRIGHTNESS 64
// Define the array of leds
CRGB leds[NUM_LEDS];
CRGBPalette16 currentPalette;
TBlendType currentBlending;
#define UPDATES_PER_SECOND 100
int x = 0;
void setup() {
Wire.begin(8); // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
//Fast LED
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.setBrightness( BRIGHTNESS );
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
}
void loop() {
static uint8_t startIndex = 0;
startIndex = startIndex + 5; /* motion speed */
uint8_t brightness = 255;
if (x == 0) {
FillLEDsFromPaletteColors( startIndex,6,9);
FastLED.show();
FastLED.delay(100 / UPDATES_PER_SECOND);
}
if (x == 1) {
FillLEDsFromPaletteColors( startIndex,6,9);
FastLED.show();
FastLED.delay(100 / UPDATES_PER_SECOND);
}
if (x == 2) {
FillLEDsFromPaletteColors( startIndex,9,12);
FastLED.show();
FastLED.delay(100 / UPDATES_PER_SECOND);
}
if (x == 3) {
FillLEDsFromPaletteColors( startIndex,9,12);
FastLED.show();
FastLED.delay(100 / UPDATES_PER_SECOND);
}
if (x == 4) {
FillLEDsFromPaletteColors( startIndex,12,15);
FastLED.show();
FastLED.delay(100 / UPDATES_PER_SECOND);
}
if (x == 5) {
FillLEDsFromPaletteColors( startIndex,12,15);
FastLED.show();
FastLED.delay(100 / UPDATES_PER_SECOND);
}
if (x == 6) {
FillLEDsFromPaletteColors( startIndex,15,18);
FastLED.show();
FastLED.delay(100 / UPDATES_PER_SECOND);
}
if (x == 7) {
FillLEDsFromPaletteColors( startIndex,15,18);
FastLED.show();
FastLED.delay(100 / UPDATES_PER_SECOND);
}
if (x == 8) {
FillLEDsFromPaletteColors( startIndex,0,3);
FastLED.show();
FastLED.delay(100 / UPDATES_PER_SECOND);
}
if (x == 9) {
FillLEDsFromPaletteColors( startIndex,0,3);
FastLED.show();
FastLED.delay(100 / UPDATES_PER_SECOND);
}
if (x == 10) {
FillLEDsFromPaletteColors( startIndex,3,6);
FastLED.show();
FastLED.delay(100 / UPDATES_PER_SECOND);
}
if (x == 11) {
FillLEDsFromPaletteColors( startIndex,3,6);
FastLED.show();
FastLED.delay(100 / UPDATES_PER_SECOND);
}
if (x == 12) {
FillLEDsFromPaletteColors( startIndex,9,12);
FastLED.show();
FastLED.delay(100 / UPDATES_PER_SECOND);
}
if (x == 15){
for(int i = 0; i < NUM_LEDS; i++){
// Turn the LED on, then pause
leds[i] = CRGB::Red;
FastLED.show();
delay(10);
// Now turn the LED off, then pause
leds[i] = CRGB::Black;
FastLED.show();
delay(10);
}
}
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany) {
while (1 < Wire.available()) { // loop through all but the last
char c = Wire.read(); // receive byte as a character
Serial.print(c); // print the character
}
x = Wire.read(); // receive byte as an integer
Serial.println(x); // print the integer
}
void FillLEDsFromPaletteColors( uint8_t colorIndex,int ledStart,int ledEnd)
{
uint8_t brightness = 255;
for( int i = ledStart; i < ledEnd; i++) {
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
colorIndex += 3;
}
}