Cheatsheet¶
A more in-depth documentation of the library can be found in the iFlex Workshop documentation.
0.5 Arduino Cheatsheet¶
This is a cheatsheet with the most commonly used syntax while programming using the arduino IDE.
1. Introduction¶
This is a cheatsheet for the iFlexPro library written by LUMITRONIX, for usage with the DevKit available from us.
It will go over all the different submodules that are a part of the iFlexPro DevKit, and shows the various available functions that exist within the library for each of them.
3. Display¶
First, the LCD display has to be declared via the following commands:
LUMITRONIX_iFlexWorkShop_Display display;
Throughout this section, display will be used as an example name for the object we have just declared.
The name can be chosen at will, simply replace our placeholder with your name of choice.
We can then initialize it within our setup function like this:
void setup() {
display.begin();
}
The Pins for the 16x2 LCD Screen are preconfigured as followed:
- Pins
- RS: 16EN: 17D4: 18D5: 19D6: 7D7: 6
3.1 Set()¶
display.Set(char const* lineOneInput, char const* lineTwoInput)
Prints out the text given to the function as parameters to the LCD screen.
void loop() {
// displays Hello World! on the first line of the LCD Display
display.Set("Hello World!);
// displays Hello on the first line, and World! on the second line of the LCD Display
display.Set("Hello", "World!");
// displays nothing on the first line, and Hi! on the second line of the LCD Display
display.Set(' ', "Hi!");
}
3.2 SetLineOne() and SetLineTwo()¶
display.SetLineOne(char const* Input);
display.SetLineTwo(char const* Input);
These functions works similarly to the Set() function. They also display given input to the LCD Display, they are only able to display input on one line of the display instead of both of them.
The line that can be accessed, can be seen simply by taking a look at the function names. SetLineOne sets the first line, SetLineTwo the second one.
Here is the example from the Set() section, using SetLineOne() and SetLineTwo() instead.
void loop() {
// displays Hello World! on the first line of the LCD Display
display.SetLineOne("Hello World!");
// displays Hello on the first line, and World! on the second line of the LCD Display
display.SetLineOne("Hello");
display.SetLineTwo("World!");
// displays nothing on the first ine, and Hi! on the second line of the LCD Display
display.SetLineOne(' ');
display.SetLineTwo("Hi!");
}
4. Barreljack/PowerSense¶
These Functions are used for external power sensing on the iFlex Workshop module
First, the barreljack has to be declared via the following commands:
LUMITRONIX_IFlexWorkShop_PowerSense powerSense;
Throughout this section, powerSense will be used as an example name for the object we have just declared.
The name can be chosen at will, simply replace our placeholder with your name of choice.
We can then initialize it within our setup function like this:
void setup() {
powerSense.begin();
}
Pin 4 is preconfigured as the sense pin for the barreljack connection. Pin 0 is preconfigured as the sense pin for external +5V( from the USB connection of the Arduino Nano V3 for example)
4.1 LUMITRONIX_CHECK_EXTERNAL_POWER¶
LUMITRONIX_CHECK_EXTERNAL_POWER;
This is a preconfigured function which checks for both BarrelJack connection and external +5V
Depending on which of the 2 you are missing you will get an error message displayed on the LCD Display.
4.2 IsBarrelJackPluggedIn() and Is5VExtPresent()¶
powerSense.isBarrelJackPluggedIn();
powerSense.is5VExtPresent();
The function isBarrelJackPluggedIn() checks wheter or not the barreljack is connected. It returns True if it is connected, and False when it isnt.
The function is5VExtPresent() checks wheter or not there is a external 5V power supply present. It returns True if there is, and False if there isnt.
void loop() {
// runs if isBarrelJackPluggedIn() returns false
if (!powerSense.IsBarrelJackPluggedIn()) {
display.Set(
"Barrel Jack"k
"unplugged"
);
return;
}
// runs if is5VExtPresent() returns false
if (!powerSense.Is5VExtPresent()) {
display.Set(
"Check PSU",
"+5V-EXT missing"
);
return;
}
}
5. IFlexPro¶
First, the iFlexPro has to be declared via the following commands:
LUMITRONIX_iFLexPro iFlexPro {
LUMITRONIX_IFLEX_WORKSHOP_PRO_LEDS // preconfigured to 11, simply change if you have a different amount of LEDS
LUMITRONIX_IFLEX_WORKSHOP_PRO_PIN // preconfigured to 2, simply change if you want to use a different pin to signal
Throughout this section, iFlexPro will be used as an example name for the object we have just declared.
The name can be chosen at will, simply replace our placeholder with your name of choice.
We can then initialize it within our setup function like this:
void setup() {
iFlexPro.begin();
}
5.1 SetPixelColor()¶
iFlexPro.SetPixelColor(uint16_t led, uint8_t red, uint8_t green, uint8_t blue, uint8_t white);
// led starts at 0
This function sets the color of the specified LED.
void loop() {
// sets all of the LEDs to white
iFlexPro.SetPixelColor(0, 0, 0, 0, 255);
iFlexPro.SetPixelColor(1, 0, 0, 0, 255);
iFlexPro.SetPixelColor(2, 0, 0, 0, 255);
iFlexPro.SetPixelColor(3, 0, 0, 0, 255);
iFlexPro.SetPixelColor(4, 0, 0, 0, 255);
iFlexPro.SetPixelColor(5, 0, 0, 0, 255);
iFlexPro.SetPixelColor(6, 0, 0, 0, 255);
iFlexPro.SetPixelColor(7, 0, 0, 0, 255);
iFlexPro.SetPixelColor(8, 0, 0, 0, 255);
iFlexPro.SetPixelColor(9, 0, 0, 0, 255);
iFlexPro.SetPixelColor(10, 0, 0, 0, 255);
}
5.2 Show()¶
Once all the desired pixelcolors have been set via the SetPixelColor() function, this function then sends them to the iFlexPro.
iFlexPro.Show();
6. Pulse¶
First, pulse has to be declared via the following commands:
LUMITRONIX_iFlexWorkShop_Pulse pulse;
Throughout this section, pulse will be used as an example name for the object we have just declared.
The name can be chosen at will, simply replace our placeholder with your name of choice.
We can then initialize it within our setup function like this:
void setup() {
pulse.begin();
}
The pulse function automatically creates a pulse animation based on the parameters you pass to it.
pulse(float const period, float const offset);
This function is used in the SetPixelColor function.
The following example creates a white wave-like effect on the iFlexPro.
void loop() {
iFlexPro.SetPixelColor( 0, 0, 0, 0, pulse(2000.f, 0.f));
iFlexPro.SetPixelColor( 1, 0, 0, 0, pulse(2000.f, 100.f));
iFlexPro.SetPixelColor( 2, 0, 0, 0, pulse(2000.f, 200.f));
iFlexPro.SetPixelColor( 3, 0, 0, 0, pulse(2000.f, 300.f));
iFlexPro.SetPixelColor( 4, 0, 0, 0, pulse(2000.f, 400.f));
iFlexPro.SetPixelColor( 5, 0, 0, 0, pulse(2000.f, 500.f));
iFlexPro.SetPixelColor( 6, 0, 0, 0, pulse(2000.f, 600.f));
iFlexPro.SetPixelColor( 7, 0, 0, 0, pulse(2000.f, 700.f));
iFlexPro.SetPixelColor( 8, 0, 0, 0, pulse(2000.f, 800.f));
iFlexPro.SetPixelColor( 9, 0, 0, 0, pulse(2000.f, 900.f));
iFlexPro.SetPixelColor( 10, 0, 0, 0, pulse(2000.f, 1000.f));
}