Difference between revisions of "ES101 - Lesson 10 : Board IO"
From Embedded Systems Learning Academy
(→Assignment) |
(→Sample Code) |
||
Line 15: | Line 15: | ||
== Sample Code == | == Sample Code == | ||
<syntaxhighlight lang="c"> | <syntaxhighlight lang="c"> | ||
+ | #include <stdio.h> | ||
+ | #include "utilities.h" // delay_ms() | ||
+ | #include "io.hpp" // board IO | ||
+ | |||
int main(void) | int main(void) | ||
{ | { | ||
− | // Just by typing Board | + | // Just by typing Board IOname, such as : "AS" |
// should give you functions you can invoke of Acceleration Sensor | // should give you functions you can invoke of Acceleration Sensor | ||
// See the reference assignment link above. | // See the reference assignment link above. | ||
+ | // Also open up io.hpp to get list of names of Board IO | ||
while(1) | while(1) | ||
{ | { | ||
− | // Get the value of the switch | + | // Get the value of the switch by using SW object |
bool switch_one = SW.getSwitch(1); | bool switch_one = SW.getSwitch(1); | ||
− | // Light up an LED | + | // Light up an LED by using LE object |
if(switch_one) { | if(switch_one) { | ||
LE.on(1); | LE.on(1); | ||
} | } | ||
− | // Get temperature | + | // Get temperature using TS object |
int temperature = TS.getCelsius(); | int temperature = TS.getCelsius(); | ||
+ | |||
+ | // Display on LED display using LD object | ||
LD.setNumber(temperature); | LD.setNumber(temperature); | ||
Revision as of 03:15, 31 October 2012
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 value on 7-Segment LED Display
- Note that maximum light sensor value is 4096, calculate the percent first, then display on 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
- 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.
Sample Code
#include <stdio.h>
#include "utilities.h" // delay_ms()
#include "io.hpp" // board IO
int main(void)
{
// Just by typing Board IOname, such as : "AS"
// should give you functions you can invoke of Acceleration Sensor
// See the reference assignment link above.
// Also open up io.hpp to get list of names of Board IO
while(1)
{
// Get the value of the switch by using SW object
bool switch_one = SW.getSwitch(1);
// Light up an LED by using LE object
if(switch_one) {
LE.on(1);
}
// Get temperature using TS object
int temperature = TS.getCelsius();
// Display on LED display using LD object
LD.setNumber(temperature);
// Read the documentation to complete the rest of the assignment.
}
return 0;
}