Utilities Library
WaspUtils.h ; WaspUtils.cpp
To start using the Waspmote Utilities library, an object from class
'WaspUtils'
must be created. This object, called Utils
, is created inside the Waspmote Utilities library and it is public to all libraries. It is used through the guide to show how the Waspmote Utilities library works.When creating this constructor, no variables are initialized.
There are some constants defined in 'WaspUtils.h' used to make it easier the understanding of the code.
These functions are capable of changing the state of the LEDs. There are two programmable LEDs in Waspmote: a green LED and a red LED.
LED1
refers to the green LED. LED0
refers to the red LED. It is possible to change their state, to get their state and to blink both LEDs for a specific time.
Figure: Programmable LEDs in Waspmote
The function
setLED()
changes the state of the LEDs. It is necessary to indicate two different inputs: the LED which is set and the state to be set.Example of use:
{
// 1. set LEDs ON
Utils.setLED( LED1, LED_ON); // Sets the green LED ON
Utils.setLED( LED0, LED_ON); // Sets the red LED ON
// 2. set LEDs OFF
Utils.setLED( LED1, LED_OFF); // Sets the green LED OFF
Utils.setLED( LED0, LED_OFF); // Sets the red LED OFF
// 3. Get LEDs state
uint8_t state1=Utils.getLED(LED1); // Gets the state of LED1
uint8_t state0=Utils.getLED(LED0); // Gets the state of LED0
}
The function
blinkLEDs()
blinks both LEDs once using the time input specified as argument in this function in milliseconds units.Example of use:
{
Utils.blinkLEDs(1000); // Blink both LEDs during 1000 ms
}
The function
blinkRedLED()
blinks the red LED once during 200 ms. It is possible to modify the number of times it blinks and the amount of time used in each blinking.Example of use:
{
Utils.blinkRedLED(); // blink once
Utils.blinkRedLED(500); // blink once during 500 ms
Utils.blinkRedLED(500, 3); // blink 3 times during 500 ms each time
}
The function
blinkGreenLED()
blinks the green LED once during 200 ms. It is possible to modify the number of times it blinks and the amount of time used in each blinking.Example of use:
{
Utils.blinkGreenLED(); // blink once
Utils.blinkGreenLED(500); // blink once during 500 ms
Utils.blinkGreenLED(500, 3); // blink 3 times during 500 ms each time
}
This is the microcontroller's EEPROM (4 KB) non-volatile memory. EEPROM addresses from 0 to 1023 are reserved by Waspmote API to save important data, so they must not be over-written. Thus, the available storage addresses go from 1024 to 4095.
Reserved | Available |
0 1023 | 1024 4095 |
Figure: EEPROM availability overview
The function that writes the EEPROM is
Utils.writeEEPROM()
. This function does not permit to write reserved EEPROM addresses.Example of use:
{
Utils.writeEEPROM(1024,'B'); // Write the value 'B' in the address 1024
uint8_t data=Utils.readEEPROM(1024); // Reads the value stored in the address 1024
}
This function reads the Waspmote unique serial identifier. This identifier is composed by 8 bytes.
Example of use:
{
unsigned long id = 0;
id = Utils.readSerialID();
}
Convert from long int to string:
{
char number[20];
Utils.long2array(1356, number); // Gets the number '1356' into the string
}
Convert from float to string:
{
char number[20];
Utils.float2String(134.54342, number, 3); // Convert 134.54342 from float to string (3 decimals)
}
AVR Libc Library allows the user to convert between different variable types. This is a list with some supported function prototypes:
Convert string to int (2 bytes):
{
int number = atoi(\"2341\");
}
Convert from string to long integer (4 bytes):
{
long int number = atol(\"143413\");
}
Last modified 2yr ago