initial upload
After Width: | Height: | Size: 73 KiB |
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
Grove LED Bar - Basic Control Example
|
||||
This example will show you how to use the setBits() function of this library.
|
||||
Set any combination of LEDs using 10 bits.
|
||||
Least significant bit controls the first LED.
|
||||
|
||||
The setBits() function sets the current state, one bit for each LED.
|
||||
First 10 bits from the right control the 10 LEDs.
|
||||
|
||||
eg. 0b00000jihgfedcba
|
||||
a = LED 1, b = LED 2, c = LED 3, etc.
|
||||
|
||||
dec hex binary
|
||||
0 = 0x0 = 0b000000000000000 = all LEDs off
|
||||
5 = 0x05 = 0b000000000000101 = LEDs 1 and 3 on, all others off
|
||||
341 = 0x155 = 0b000000101010101 = LEDs 1,3,5,7,9 on, 2,4,6,8,10 off
|
||||
1023 = 0x3ff = 0b000001111111111 = all LEDs on
|
||||
| |
|
||||
10 1
|
||||
|
||||
The bits >10 are ignored, shown here as x: 0bxxxxx0000000000
|
||||
|
||||
Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette
|
||||
*/
|
||||
|
||||
#include <Grove_LED_Bar.h>
|
||||
|
||||
// Arduino Clock pin, Data pin, Orientation
|
||||
// Grove_LED_Bar bar(7, 6, 0);
|
||||
|
||||
// LaunchPad Clock pin, Data pin, Orientation
|
||||
Grove_LED_Bar bar(35, 36, 0);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// nothing to initialize
|
||||
bar.begin();
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Turn on all LEDs
|
||||
bar.setBits(0x3ff);
|
||||
delay(1000);
|
||||
|
||||
// Turn off all LEDs
|
||||
bar.setBits(0x0);
|
||||
delay(1000);
|
||||
|
||||
// Turn on LED 1
|
||||
// 0b000000000000001 can also be written as 0x1:
|
||||
bar.setBits(0b000000000000001);
|
||||
delay(1000);
|
||||
|
||||
// Turn on LEDs 1 and 3
|
||||
// 0b000000000000101 can also be written as 0x5:
|
||||
bar.setBits(0b000000000000101);
|
||||
delay(1000);
|
||||
|
||||
// Turn on LEDs 1, 3, 5, 7, 9
|
||||
bar.setBits(0x155);
|
||||
delay(1000);
|
||||
|
||||
// Turn on LEDs 2, 4, 6, 8, 10
|
||||
bar.setBits(0x2AA);
|
||||
delay(1000);
|
||||
|
||||
// Turn on LEDs 1, 2, 3, 4, 5
|
||||
// 0b000000000011111 == 0x1F
|
||||
bar.setBits(0b000000000011111);
|
||||
delay(1000);
|
||||
|
||||
// Turn on LEDs 6, 7, 8, 9, 10
|
||||
// 0b000001111100000 == 0x3E0
|
||||
bar.setBits(0b000001111100000);
|
||||
delay(1000);
|
||||
}
|
||||
|
After Width: | Height: | Size: 71 KiB |
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
Grove LED Bar - Bounce Example
|
||||
This example will show you how to use getBits() function of this library.
|
||||
The getBits() function returns the current state so you can modify it.
|
||||
Use the setBits() function to save the new state.
|
||||
|
||||
Ported to MSP-EXP430F5529, and TM4C123 (Tiva C) by Cameron P. LaFollette
|
||||
|
||||
*/
|
||||
|
||||
#include <Grove_LED_Bar.h>
|
||||
|
||||
// Arduino Clock pin, Data pin, Orientation
|
||||
// Grove_LED_Bar bar(7, 6, 0);
|
||||
|
||||
// LaunchPad Clock pin, Data pin, Orientation
|
||||
Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
unsigned int state;
|
||||
|
||||
void setup()
|
||||
{
|
||||
// nothing to initialize
|
||||
bar.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Switch on the first two LEDs
|
||||
bar.setLevel(2);
|
||||
|
||||
// Get the current state (which is 0x3)
|
||||
state = bar.getBits();
|
||||
|
||||
// Bounce to the right
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
// Bit shift left and update
|
||||
state <<= 1;
|
||||
bar.setBits(state);
|
||||
delay(200);
|
||||
}
|
||||
|
||||
// Bounce to the left
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
// Bit shift right and update
|
||||
state >>= 1;
|
||||
bar.setBits(state);
|
||||
delay(200);
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 68 KiB |
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
Grove LED Bar - Control Single LED Example
|
||||
This example will show you how to use the setLed() function of this library.
|
||||
There are 10 LEDs in the Grove LED Bar.
|
||||
Use this method to set a single LED.
|
||||
|
||||
Syntax setLed(led, state)
|
||||
led (1-10)
|
||||
state (0=off, 1=on)
|
||||
|
||||
Ported for TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette
|
||||
*/
|
||||
|
||||
#include <Grove_LED_Bar.h>
|
||||
//Arduino
|
||||
//Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
// LaunchPad
|
||||
Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
// nothing to initialize
|
||||
bar.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Set LED 3 on
|
||||
bar.setLed(3, 1);
|
||||
delay(500);
|
||||
|
||||
// Set LED 5 on
|
||||
bar.setLed(5, 1);
|
||||
delay(500);
|
||||
|
||||
// Set LED 7 on
|
||||
bar.setLed(7, 1);
|
||||
delay(500);
|
||||
|
||||
// Set LED 3 off
|
||||
bar.setLed(3, 0);
|
||||
delay(500);
|
||||
|
||||
// Set LED 5 off
|
||||
bar.setLed(5, 0);
|
||||
delay(500);
|
||||
|
||||
// Set LED 7 off
|
||||
bar.setLed(7, 0);
|
||||
delay(500);
|
||||
|
||||
// Turn all LEDs on
|
||||
for (int i = 1; i <= 10; i++)
|
||||
{
|
||||
bar.setLed(i, 1);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
// Turn all LEDs off
|
||||
for (int i = 1; i <= 10; i++)
|
||||
{
|
||||
bar.setLed(i, 0);
|
||||
delay(500);
|
||||
}
|
||||
}
|
After Width: | Height: | Size: 62 KiB |
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
Grove LED Bar - Level Example
|
||||
This example will show you how to use setLevel() function of this library.
|
||||
The setLevel() function illuminates the given number of LEDs from either side.
|
||||
|
||||
Syntax setLevel(level)
|
||||
0 = all LEDs off
|
||||
5 = 5 LEDs on
|
||||
10 = all LEDs on
|
||||
|
||||
Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette
|
||||
*/
|
||||
|
||||
#include <Grove_LED_Bar.h>
|
||||
|
||||
|
||||
// Arduino Clock pin, Data pin, Orientation
|
||||
// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
// LaunchPad Clock pin, Data pin, Orientation
|
||||
Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
void setup()
|
||||
{
|
||||
// nothing to initialize
|
||||
bar.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Walk through the levels
|
||||
for (int i = 0; i <= 10; i++)
|
||||
{
|
||||
bar.setLevel(i);
|
||||
delay(100);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
# Examples
|
||||
|
||||
## BasicControl
|
||||

|
||||
|
||||
----
|
||||
|
||||
## Bounce
|
||||

|
||||
|
||||
----
|
||||
|
||||
## ControlSingleLed
|
||||

|
||||
|
||||
----
|
||||
|
||||
## Level
|
||||

|
||||
|
||||
----
|
||||
|
||||
## Random
|
||||

|
||||
|
||||
----
|
||||
|
||||
## Reverse
|
||||

|
||||
|
||||
----
|
||||
|
||||
## Toggle
|
||||

|
||||
|
||||
----
|
||||
|
||||
## Walk
|
||||

|
||||
|
||||
----
|
||||
|
||||
## WalkMultiple
|
||||
Same as the Walk example, only with two Grove LED bars, the second initialised in reverse mode.
|
After Width: | Height: | Size: 92 KiB |
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
Grove LED Bar - Random Example
|
||||
This example will show you how to use setBits() function of this library.
|
||||
Set any combination of LEDs using 10 bits.
|
||||
|
||||
Ported for MSP-EXP430F5529 TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette
|
||||
*/
|
||||
|
||||
#include <Grove_LED_Bar.h>
|
||||
|
||||
// Arduino Clock pin, Data pin, Orientation
|
||||
// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
// LaunchPad Clock pin, Data pin, Orientation
|
||||
Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
void setup()
|
||||
{
|
||||
// nothing to initialize
|
||||
bar.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Display a random value between 0 (all LEDs off) and 1023 (all LEDs on)
|
||||
bar.setBits(random(1024));
|
||||
delay(50);
|
||||
}
|
After Width: | Height: | Size: 107 KiB |
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
Grove LED Bar - Reverse Example
|
||||
This example will show you how to use setGreenToRed() function of this library.
|
||||
The function is used to reverse the orientation of the LED Bar.
|
||||
Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette
|
||||
*/
|
||||
|
||||
#include <Grove_LED_Bar.h>
|
||||
|
||||
// The 3rd parameter sets the initial orientation
|
||||
// 0 = green to red, 1 = red to green
|
||||
// You can always change it at runtime with the setGreenToRed() function
|
||||
|
||||
// Arduino Clock pin, Data pin, Orientation
|
||||
// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
// LaunchPad Clock pin, Data pin, Orientation
|
||||
Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
void setup()
|
||||
{
|
||||
// nothing to initialize
|
||||
bar.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Start as red to green
|
||||
// Walk through the 10 levels
|
||||
for (int i = 0; i <= 10; i++)
|
||||
{
|
||||
bar.setLevel(i);
|
||||
delay(200);
|
||||
}
|
||||
bar.setLevel(0);
|
||||
|
||||
// Swich to green to red
|
||||
bar.setGreenToRed(1);
|
||||
|
||||
// Walk through the 10 levels
|
||||
for (int i = 0; i <= 10; i++)
|
||||
{
|
||||
bar.setLevel(i);
|
||||
delay(200);
|
||||
}
|
||||
bar.setLevel(0);
|
||||
|
||||
// Switch back to red to green
|
||||
bar.setGreenToRed(0);
|
||||
delay(200);
|
||||
|
||||
// Walk through the levels
|
||||
// Each reverse keeps the previously set level
|
||||
for (int i = 1; i <= 10; i++)
|
||||
{
|
||||
bar.setLevel(i);
|
||||
delay(500);
|
||||
|
||||
bar.setGreenToRed(1);
|
||||
delay(500);
|
||||
|
||||
bar.setGreenToRed(0);
|
||||
}
|
||||
bar.setLevel(0);
|
||||
}
|
After Width: | Height: | Size: 63 KiB |
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
Grove LED Bar - Toggle Example
|
||||
This example will show you how to use toggleLed() function of this library.
|
||||
The function lets you set a single led to the opposite of it's current value.
|
||||
|
||||
Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette
|
||||
*/
|
||||
|
||||
#include <Grove_LED_Bar.h>
|
||||
|
||||
// Arduino Clock pin, Data pin, Orientation
|
||||
// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
// LaunchPad Clock pin, Data pin, Orientation
|
||||
Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
void setup()
|
||||
{
|
||||
// nothing to initialize
|
||||
bar.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Start with all LEDs illuminated
|
||||
bar.setLevel(10);
|
||||
delay(1000);
|
||||
|
||||
// Turn off LED 3
|
||||
bar.toggleLed(3);
|
||||
delay(1000);
|
||||
|
||||
// Turn on LED 3
|
||||
bar.toggleLed(3);
|
||||
delay(1000);
|
||||
|
||||
// Switch off all LEDs
|
||||
bar.setLevel(0);
|
||||
delay(1000);
|
||||
|
||||
// Turn on LED 7
|
||||
bar.toggleLed(7);
|
||||
delay(1000);
|
||||
|
||||
// Turn off LED 7
|
||||
bar.toggleLed(7);
|
||||
delay(1000);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
Grove LED Bar - Control Single LED Example
|
||||
...
|
||||
|
||||
Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette
|
||||
*/
|
||||
|
||||
#include <Grove_LED_Bar.h>
|
||||
|
||||
// Arduino Clock pin, Data pin, Orientation
|
||||
// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
// LaunchPad Clock pin, Data pin, Orientation
|
||||
Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
// nothing to initialize
|
||||
bar.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// Simulate police LED lights using setLed method
|
||||
for (float i = 0; i < 1.1; i += .125f) {
|
||||
bar.setLed(1, i);
|
||||
bar.setLed(2, i);
|
||||
bar.setLed(3, 1 - i);
|
||||
bar.setLed(4, 1 - i);
|
||||
delay(50);
|
||||
};
|
||||
|
||||
for (float i = 0; i < 1.1; i += .125f) {
|
||||
bar.setLed(1, 1 - i);
|
||||
bar.setLed(2, 1 - i);
|
||||
bar.setLed(3, i);
|
||||
bar.setLed(4, i);
|
||||
delay(50);
|
||||
};
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
Grove LED Bar - Brightness Level Example
|
||||
...
|
||||
Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette
|
||||
*/
|
||||
|
||||
#include <Grove_LED_Bar.h>
|
||||
|
||||
// Arduino Clock pin, Data pin, Orientation
|
||||
// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
// LaunchPad Clock pin, Data pin, Orientation
|
||||
Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
void setup()
|
||||
{
|
||||
// nothing to initialize
|
||||
bar.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
bar.setGreenToRed(false);
|
||||
for (float i = 0; i < 10.1; i += 0.125) {
|
||||
bar.setLevel(i);
|
||||
delay(25);
|
||||
};
|
||||
for (float i = 0; i < 10.1; i += 0.125) {
|
||||
bar.setLevel(10-i);
|
||||
delay(25);
|
||||
};
|
||||
|
||||
// Change orientation
|
||||
bar.setGreenToRed(true);
|
||||
for (float i = 0; i < 10.1; i += 0.125) {
|
||||
bar.setLevel(i);
|
||||
delay(25);
|
||||
};
|
||||
for (float i = 0; i < 10.1; i += 0.125) {
|
||||
bar.setLevel(10-i);
|
||||
delay(25);
|
||||
};
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
Grove LED Bar - Wave Example
|
||||
...
|
||||
Ported for MSP-EXP430F5529, TM4C123 (Tiva C) by Cameron P. LaFollette
|
||||
*/
|
||||
|
||||
#include <Grove_LED_Bar.h>
|
||||
|
||||
// Arduino Clock pin, Data pin, Orientation
|
||||
// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
// LaunchPad Clock pin, Data pin, Orientation
|
||||
Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
void setup()
|
||||
{
|
||||
// nothing to initialize
|
||||
bar.begin();
|
||||
}
|
||||
|
||||
// Frames of continuous waves
|
||||
unsigned char state[] =
|
||||
{
|
||||
0b11111111,
|
||||
0b01111111,
|
||||
0b00111111,
|
||||
0b00011111,
|
||||
0b00001111,
|
||||
0b00000111,
|
||||
0b00000011,
|
||||
0b00000001,
|
||||
0b00000000,
|
||||
0b00000001,
|
||||
0b00000011,
|
||||
0b00000111,
|
||||
0b00001111,
|
||||
0b00011111,
|
||||
0b00111111,
|
||||
0b01111111,
|
||||
0b11111111,
|
||||
0b01111111,
|
||||
0b00111111,
|
||||
0b00011111,
|
||||
0b00001111,
|
||||
0b00000111,
|
||||
0b00000011,
|
||||
0b00000001,
|
||||
0b00000000
|
||||
};
|
||||
|
||||
void loop()
|
||||
{
|
||||
for (byte i = 0; i < (sizeof(state)-9); i++) {
|
||||
bar.setBits((unsigned int)state[i]);
|
||||
delay(50);
|
||||
};
|
||||
}
|
After Width: | Height: | Size: 973 KiB |
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
Grove LED Bar - Walk Example
|
||||
This example will show you how to use setBits() function of this library.
|
||||
Set any combination of LEDs using 10 bits.
|
||||
This example walks through all 1024 (2^10) possible combinations.
|
||||
|
||||
Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette
|
||||
*/
|
||||
|
||||
#include <Grove_LED_Bar.h>
|
||||
|
||||
// Arduino Clock pin, Data pin, Orientation
|
||||
// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
// LaunchPad Clock pin, Data pin, Orientation
|
||||
Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
// nothing to initialize
|
||||
bar.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// 0 = 0x0 = all 10 LEDs turned off
|
||||
// 1023 = 0x3FF = all 10 LEDs lit up
|
||||
for (int i = 0; i <= 1023; i++)
|
||||
{
|
||||
bar.setBits(i);
|
||||
delay(50);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
Grove LED Bar - Walk Multiple Example
|
||||
This example will show you how to use setBits() function of this library.
|
||||
Set any combination of LEDs using 10 bits.
|
||||
This example walks through all 1024 (2^10) possible combinations on two LED Bars.
|
||||
|
||||
Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette
|
||||
*/
|
||||
|
||||
#include <Grove_LED_Bar.h>
|
||||
|
||||
// Arduino Clock pin, Data pin, Orientation
|
||||
// Grove_LED_Bar bar1(9, 8, 0); // Clock pin, Data pin, Orientation
|
||||
//Grove_LED_Bar bar2(7, 6, 1); // Clock pin, Data pin, Orientation
|
||||
|
||||
// LaunchPad Clock pin, Data pin, Orientation
|
||||
Grove_LED_Bar bar1(37, 38, 0); // Clock pin, Data pin, Orientation
|
||||
Grove_LED_Bar bar2(35, 36, 0); // Clock pin, Data pin, Orientation
|
||||
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
// nothing to initialize
|
||||
bar1.begin();
|
||||
bar2.begin();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// 0 = 0x0 = all 10 LEDs turned off
|
||||
// 1023 = 0x3FF = all 10 LEDs lit up
|
||||
for (int i = 0; i <= 1023; i++)
|
||||
{
|
||||
bar1.setBits(i);
|
||||
bar2.setBits(i);
|
||||
delay(50);
|
||||
}
|
||||
}
|