source: rtos_arduino/trunk/examples/NCESIoT/rca_app.cpp@ 226

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

Groveモジュールを使用したサンプルの追加

File size: 6.2 KB
Line 
1#include "rca.h"
2
3#define SERVO
4//#define ULTRASONIC
5//#define LCD_ULTRASONIC
6//#define LCD_ULTRASONIC_SERVO /* define RCA_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
93void setup()
94{
95 Serial.begin(115200);
96}
97void loop()
98{
99 long RangeInCentimeters;
100 RangeInCentimeters = ultrasonic.MeasureInCentimeters(); // two measurements should keep an interval
101 Serial.print(RangeInCentimeters);//0~400cm
102 Serial.println(" cm");
103 delay(250);
104}
105
106#endif /* ULTRASONIC */
107
108#ifdef LCD_ULTRASONIC
109
110#include <Wire.h>
111#include <SeeedGrayOLED.h>
112#include <avr/pgmspace.h>
113#include "Ultrasonic.h"
114
115Ultrasonic ultrasonic(3);
116
117void setup()
118{
119 Wire.begin();
120 SeeedGrayOled.init(); //initialize SEEED OLED display
121 SeeedGrayOled.clearDisplay(); //Clear Display.
122 SeeedGrayOled.setNormalDisplay(); //Set Normal Display Mode
123 SeeedGrayOled.setVerticalMode(); // Set to vertical mode for displaying text
124}
125
126void loop()
127{
128 long RangeInCentimeters;
129
130 SeeedGrayOled.setTextXY(0,0); //set Cursor to ith line, 0th column
131 SeeedGrayOled.setGrayLevel(15); //Set Grayscale level. Any number between 0 - 15.
132 RangeInCentimeters = ultrasonic.MeasureInCentimeters(); // two measurements should keep an interval
133 SeeedGrayOled.putNumber(RangeInCentimeters);//0~400cm
134 SeeedGrayOled.putString(" cm ");
135 delay(250);
136}
137#endif /* LCD_ULTRASONIC */
138
139#ifdef LCD_ULTRASONIC_SERVO
140
141#include <Wire.h>
142#include <SeeedGrayOLED.h>
143#include <avr/pgmspace.h>
144#include "Ultrasonic.h"
145
146Ultrasonic ultrasonic(3);
147
148void setup()
149{
150 Wire.begin();
151 SeeedGrayOled.init(); //initialize SEEED OLED display
152 SeeedGrayOled.clearDisplay(); //Clear Display.
153 SeeedGrayOled.setNormalDisplay(); //Set Normal Display Mode
154 SeeedGrayOled.setVerticalMode(); // Set to vertical mode for displaying text
155}
156
157void loop()
158{
159 long RangeInCentimeters;
160
161 SeeedGrayOled.setTextXY(0,0); //set Cursor to ith line, 0th column
162 SeeedGrayOled.setGrayLevel(15); //Set Grayscale level. Any number between 0 - 15.
163 RangeInCentimeters = ultrasonic.MeasureInCentimeters(); // two measurements should keep an interval
164 SeeedGrayOled.putNumber(RangeInCentimeters);//0~400cm
165 SeeedGrayOled.putString(" cm ");
166 delay(250);
167}
168
169/* Sweep
170 by BARRAGAN <http://barraganstudio.com>
171 This example code is in the public domain.
172
173 modified 8 Nov 2013
174 by Scott Fitzgerald
175 http://arduino.cc/en/Tutorial/Sweep
176*/
177
178#include <Servo.h>
179
180Servo myservo; // create servo object to control a servo
181 // twelve servo objects can be created on most boards
182
183int pos = 0; // variable to store the servo position
184
185void task1_setup()
186{
187 myservo.attach(2); // attaches the servo on pin 9 to the servo object
188}
189
190void task1_loop()
191{
192 for(pos = 0; pos <= 180; pos += 1) // goes from 0 degrees to 180 degrees
193 { // in steps of 1 degree
194 myservo.write(pos); // tell servo to go to position in variable 'pos'
195 delay(15); // waits 15ms for the servo to reach the position
196 }
197 for(pos = 180; pos>=0; pos-=1) // goes from 180 degrees to 0 degrees
198 {
199 myservo.write(pos); // tell servo to go to position in variable 'pos'
200 delay(15); // waits 15ms for the servo to reach the position
201 }
202}
203
204#endif /* LCD_ULTRASONIC */
Note: See TracBrowser for help on using the repository browser.