Difference between revisions of "ES101 - Lesson 10 : Board IO"

From Embedded Systems Learning Academy
Jump to: navigation, search
Line 1: Line 1:
For this assignment, reference [[ 2012 SJ One Hello World Sample Project | 2012 SJ One '''Hello World''' Sample Project]] and do the following:
+
For this assignment, reference the following articles :
 +
[[ 2012 SJ One Hello World Sample Project | 2012 SJ One '''Hello World''' Sample Project]]
 +
*  [http://www.socialledge.com/docs/io_8hpp.html Board Documentation]
  
 +
=== Assignment ===
 
#  If Switch #1 is pressed, light up LED #1, else turn LED #1 off
 
#  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
 
#  If Switch #2 is pressed, display Light Sensor value on 7-Segment LED Display
Line 8: Line 11:
 
#*  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
 +
 +
== Sample Code ==
 +
<syntaxhighlight lang="c">
 +
int main(void)
 +
{
 +
    // Just by typing Board Sensor name, such as : "AS"
 +
    // should give you functions you can invoke of Acceleration Sensor
 +
    // See the reference assignment link above.
 +
    while(1)
 +
    {
 +
        // Get the value of the switch :
 +
        bool switch_one = SW.getSwitch(1);
 +
 +
        // Light up an LED :
 +
        if(switch_one) {
 +
            LE.on(1);
 +
        }
 +
 +
        // Get temperature, display on LED display :
 +
        int temperature = TS.getCelsius();
 +
        LD.setNumber(temperature);
 +
 +
        // Read the documentation to complete the rest of the assignment.
 +
    }
 +
 +
    return 0;
 +
}
 +
</syntaxhighlight>

Revision as of 17:54, 18 October 2012

For this assignment, reference the following articles :

Assignment

  1. If Switch #1 is pressed, light up LED #1, else turn LED #1 off
  2. 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
  3. If Switch #3 is pressed, display temperature in Fahrenheit on 7-Segment LED Display
  4. 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

Sample Code

int main(void)
{
    // Just by typing Board Sensor name, such as : "AS"
    // should give you functions you can invoke of Acceleration Sensor
    // See the reference assignment link above.
    while(1)
    {
        // Get the value of the switch :
        bool switch_one = SW.getSwitch(1);

        // Light up an LED :
        if(switch_one) {
            LE.on(1);
        }

        // Get temperature, display on LED display :
        int temperature = TS.getCelsius();
        LD.setNumber(temperature);

        // Read the documentation to complete the rest of the assignment.
    }

    return 0;
}