source: rtos_arduino/trunk/examples/NCESIoT/r2ca_app.cpp@ 260

Last change on this file since 260 was 260, checked in by ertl-honda, 8 years ago

マクロ名を更新.
実行モデルを変更.

File size: 6.3 KB
Line 
1#include "r2ca.h"
2
3#define SERVO
4//#define ULTRASONIC
5//#define LCD_ULTRASONIC
6//#define LCD_ULTRASONIC_SERVO /* define R2CA_NUM_TASK as 1 */
7
8#ifdef SERVO
9
10/* Sweep
11 by BARRAGAN <http://barraganstudio.com>
12 This example code is in the public domain.
13
14 modified 8 Nov 2013
15 by Scott Fitzgerald
16 http://arduino.cc/en/Tutorial/Sweep
17*/
18
19#include <Servo.h>
20
21Servo myservo; // create servo object to control a servo
22 // twelve servo objects can be created on most boards
23
24int pos = 0; // variable to store the servo position
25
26void setup()
27{
28 myservo.attach(2); // attaches the servo on pin 9 to the servo object
29}
30
31void loop()
32{
33 for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
34 { // in steps of 1 degree
35 myservo.write(pos); // tell servo to go to position in variable 'pos'
36 delay(15); // waits 15ms for the servo to reach the position
37 }
38 for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
39 {
40 myservo.write(pos); // tell servo to go to position in variable 'pos'
41 delay(15); // waits 15ms for the servo to reach the position
42 }
43}
44
45#endif /* SERVO */
46
47#ifdef ULTRASONIC
48
49/*
50 * UltrasonicDisplayOnTerm.ino
51 * Example sketch for ultrasonic ranger
52 *
53 * Copyright (c) 2012 seeed technology inc.
54 * Website : www.seeed.cc
55 * Author : LG, FrankieChu
56 * Create Time: Jan 17,2013
57 * Change Log :
58 *
59 * The MIT License (MIT)
60 *
61 * Permission is hereby granted, free of charge, to any person obtaining a copy
62 * of this software and associated documentation files (the "Software"), to deal
63 * in the Software without restriction, including without limitation the rights
64 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
65 * copies of the Software, and to permit persons to whom the Software is
66 * furnished to do so, subject to the following conditions:
67 *
68 * The above copyright notice and this permission notice shall be included in
69 * all copies or substantial portions of the Software.
70 *
71 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
72 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
73 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
74 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
75 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
76 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
77 * THE SOFTWARE.
78 */
79
80
81/***************************************************************************/
82// Function: Measure the distance to obstacles in front and print the distance
83// value to the serial terminal.The measured distance is from
84// the range 0 to 400cm(157 inches).
85// Hardware: Grove - Ultrasonic Ranger
86// Arduino IDE: Arduino-1.0
87/*****************************************************************************/
88
89#include "Ultrasonic.h"
90
91Ultrasonic ultrasonic(3);
92
93extern void task1_setup();
94
95void setup()
96{
97 Serial.begin(115200);
98}
99void loop()
100{
101 long RangeInCentimeters;
102 RangeInCentimeters = ultrasonic.MeasureInCentimeters(); // two measurements should keep an interval
103 Serial.print(RangeInCentimeters);//0~400cm
104 Serial.println(" cm");
105 delay(250);
106
107 task1_setup();
108}
109
110#endif /* ULTRASONIC */
111
112#ifdef LCD_ULTRASONIC
113
114#include <Wire.h>
115#include <SeeedGrayOLED.h>
116#include <avr/pgmspace.h>
117#include "Ultrasonic.h"
118
119Ultrasonic ultrasonic(3);
120
121void setup()
122{
123 Wire.begin();
124 SeeedGrayOled.init(); //initialize SEEED OLED display
125 SeeedGrayOled.clearDisplay(); //Clear Display.
126 SeeedGrayOled.setNormalDisplay(); //Set Normal Display Mode
127 SeeedGrayOled.setVerticalMode(); // Set to vertical mode for displaying text
128}
129
130void loop()
131{
132 long RangeInCentimeters;
133
134 SeeedGrayOled.setTextXY(0,0); //set Cursor to ith line, 0th column
135 SeeedGrayOled.setGrayLevel(15); //Set Grayscale level. Any number between 0 - 15.
136 RangeInCentimeters = ultrasonic.MeasureInCentimeters(); // two measurements should keep an interval
137 SeeedGrayOled.putNumber(RangeInCentimeters);//0~400cm
138 SeeedGrayOled.putString(" cm ");
139 delay(250);
140}
141#endif /* LCD_ULTRASONIC */
142
143#ifdef LCD_ULTRASONIC_SERVO
144
145#include <Wire.h>
146#include <SeeedGrayOLED.h>
147#include <avr/pgmspace.h>
148#include "Ultrasonic.h"
149
150Ultrasonic ultrasonic(3);
151
152void setup()
153{
154 Wire.begin();
155 SeeedGrayOled.init(); //initialize SEEED OLED display
156 SeeedGrayOled.clearDisplay(); //Clear Display.
157 SeeedGrayOled.setNormalDisplay(); //Set Normal Display Mode
158 SeeedGrayOled.setVerticalMode(); // Set to vertical mode for displaying text
159}
160
161void loop()
162{
163 long RangeInCentimeters;
164
165 SeeedGrayOled.setTextXY(0,0); //set Cursor to ith line, 0th column
166 SeeedGrayOled.setGrayLevel(15); //Set Grayscale level. Any number between 0 - 15.
167 RangeInCentimeters = ultrasonic.MeasureInCentimeters(); // two measurements should keep an interval
168 SeeedGrayOled.putNumber(RangeInCentimeters);//0~400cm
169 SeeedGrayOled.putString(" cm ");
170 delay(250);
171}
172
173/* Sweep
174 by BARRAGAN <http://barraganstudio.com>
175 This example code is in the public domain.
176
177 modified 8 Nov 2013
178 by Scott Fitzgerald
179 http://arduino.cc/en/Tutorial/Sweep
180*/
181
182#include <Servo.h>
183
184Servo myservo; // create servo object to control a servo
185 // twelve servo objects can be created on most boards
186
187int pos = 0; // variable to store the servo position
188
189void task1_setup()
190{
191 myservo.attach(2); // attaches the servo on pin 9 to the servo object
192}
193
194void loop1()
195{
196 for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
197 { // in steps of 1 degree
198 myservo.write(pos); // tell servo to go to position in variable 'pos'
199 delay(15); // waits 15ms for the servo to reach the position
200 }
201 for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
202 {
203 myservo.write(pos); // tell servo to go to position in variable 'pos'
204 delay(15); // waits 15ms for the servo to reach the position
205 }
206}
207
208#endif /* LCD_ULTRASONIC */
Note: See TracBrowser for help on using the repository browser.