Difference between revisions of "ES101 - Lesson 10 : Board IO"
From Embedded Systems Learning Academy
(→Assignment) |
|||
(3 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
For this assignment, reference the following articles : | For this assignment, reference the following articles : | ||
− | * [[ | + | * [[ SJ One Board | SJ One Board Experiments & Sample Code]] |
* [http://www.socialledge.com/docs/io_8hpp.html Board Documentation] | * [http://www.socialledge.com/docs/io_8hpp.html Board Documentation] | ||
+ | |||
=== Assignment === | === Assignment === | ||
Line 9: | Line 10: | ||
#* LED Display can only display 2 digits | #* LED Display can only display 2 digits | ||
# If Switch #3 is pressed, display temperature in Fahrenheit on 7-Segment LED Display | # If Switch #3 is pressed, display temperature in Fahrenheit on 7-Segment LED Display | ||
− | # If Switch #4 is pressed, display Acceleration Sensor's X-Axis on 7-Segment LED Display | + | # If Switch #4 is pressed, display Acceleration Sensor's X-Axis percentage on 7-Segment LED Display |
#* Note that minimum value is -1024 and maximum value is +1024. | #* Note that minimum value is -1024 and maximum value is +1024. | ||
#* You can add 1024 to this value, then calculate percentage by ((X-Axis+1024)/ 2048) * 100 | #* You can add 1024 to this value, then calculate percentage by ((X-Axis+1024)/ 2048) * 100 | ||
# The points for this assignment depends on how much you add to the program. For example, you can take advantage of the acceleration sensor's Y and Z axis and make the board more interactive. If you have a remote control with you, you can even take advantage of reading IR code received by the board, and light up some LEDs. | # The points for this assignment depends on how much you add to the program. For example, you can take advantage of the acceleration sensor's Y and Z axis and make the board more interactive. If you have a remote control with you, you can even take advantage of reading IR code received by the board, and light up some LEDs. | ||
+ | # '''Have fun!''' and play around with Board IO. Your projects depend on the creativity using these boards. | ||
== Sample Code == | == Sample Code == | ||
Line 22: | Line 24: | ||
int main(void) | int main(void) | ||
{ | { | ||
− | / | + | /* io.hpp contains the names of the board input-output devices |
− | + | * By typing SW, LE, TS, LD, or AS, it will offer you with the | |
− | + | * functions you can invoke to read values or use the device | |
− | + | */ | |
while(1) | while(1) | ||
{ | { | ||
− | / | + | /* Get sw1 value, and turn on/off led */ |
− | bool | + | bool sw1_pressed = SW.getSwitch(1); |
− | + | if(sw1_pressed) { | |
− | |||
− | if( | ||
LE.on(1); | LE.on(1); | ||
+ | } | ||
+ | else { | ||
+ | LE.off(1); | ||
} | } | ||
− | / | + | /* Get temperature using TS (temperature sensor) object */ |
− | int temperature = TS. | + | int temperature = TS.getFarenheit(); |
− | / | + | /* Use LD (LED Display) to display it */ |
LD.setNumber(temperature); | LD.setNumber(temperature); | ||
− | // | + | /* Get Acceleration sensor X-axis value */ |
+ | int xaxis = AS.getX(); | ||
} | } | ||
Latest revision as of 19:39, 15 October 2013
For this assignment, reference the following articles :
Assignment
- If Switch #1 is pressed, light up LED #1, else turn LED #1 off
- If Switch #2 is pressed, display Light Sensor percentage on 7-Segment LED Display
- Note that maximum light sensor value is 4096, calculate the percent first, then display on LED Display
- LED Display can only display 2 digits
- If Switch #3 is pressed, display temperature in Fahrenheit on 7-Segment LED Display
- If Switch #4 is pressed, display Acceleration Sensor's X-Axis percentage on 7-Segment LED Display
- Note that minimum value is -1024 and maximum value is +1024.
- You can add 1024 to this value, then calculate percentage by ((X-Axis+1024)/ 2048) * 100
- The points for this assignment depends on how much you add to the program. For example, you can take advantage of the acceleration sensor's Y and Z axis and make the board more interactive. If you have a remote control with you, you can even take advantage of reading IR code received by the board, and light up some LEDs.
- Have fun! and play around with Board IO. Your projects depend on the creativity using these boards.
Sample Code
#include <stdio.h>
#include "utilities.h" // delay_ms()
#include "io.hpp" // board IO
int main(void)
{
/* io.hpp contains the names of the board input-output devices
* By typing SW, LE, TS, LD, or AS, it will offer you with the
* functions you can invoke to read values or use the device
*/
while(1)
{
/* Get sw1 value, and turn on/off led */
bool sw1_pressed = SW.getSwitch(1);
if(sw1_pressed) {
LE.on(1);
}
else {
LE.off(1);
}
/* Get temperature using TS (temperature sensor) object */
int temperature = TS.getFarenheit();
/* Use LD (LED Display) to display it */
LD.setNumber(temperature);
/* Get Acceleration sensor X-axis value */
int xaxis = AS.getX();
}
return 0;
}