OSDN Git Service

Update samples to nxtOSEK_v212.zip (I did not check their licenses.)
[nxt-jsp/etrobo-atk.git] / nxtOSEK / samples_c++ / cpp / NxtSensors / sample.cpp
1 /* sample.cpp for TOPPERS/ATK(OSEK) */ \r
2 \r
3 // ECRobot++ API\r
4 #include "LightSensor.h"\r
5 #include "SonarSensor.h"\r
6 #include "SoundSensor.h"\r
7 #include "TouchSensor.h"\r
8 #include "Clock.h"\r
9 #include "Lcd.h"\r
10 using namespace ecrobot;\r
11 \r
12 extern "C"\r
13 {\r
14 #include "kernel.h"\r
15 #include "kernel_id.h"\r
16 #include "ecrobot_interface.h"\r
17 \r
18 LightSensor  light(PORT_1, false /* lamp off */);\r
19 SonarSensor  sonar(PORT_2);\r
20 SoundSensor    mic(PORT_3);\r
21 TouchSensor  touch(PORT_4);\r
22 \r
23 /* nxtOSEK hook to be invoked from an ISR in category 2 */\r
24 void user_1ms_isr_type2(void)\r
25 {\r
26         SleeperMonitor(); // needed for I2C device and Clock classes\r
27 }\r
28 \r
29 TASK(TaskMain)\r
30 {\r
31         Clock clock;\r
32         Lcd lcd;\r
33 \r
34         while(1)\r
35         {\r
36                 lcd.clear();\r
37                 lcd.putf("sn",   "NXT Sensors");\r
38                 lcd.putf("sddn", "1/2: ", light.getBrightness(),0, sonar.getDistance(),5);\r
39                 lcd.putf("sdd",  "3/4: ", mic.getLevel(),0, touch.isPressed(),5);\r
40                 lcd.disp();  \r
41 \r
42                 clock.wait(100);\r
43         }\r
44 }\r
45 }\r