jason berry
/
ServoTest
main.cpp@2:a6b6d93ff3cf, 2021-02-04 (annotated)
- Committer:
- jasonberry
- Date:
- Thu Feb 04 14:45:35 2021 +0000
- Revision:
- 2:a6b6d93ff3cf
- Parent:
- 0:101a12a915c6
servojason
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sam_grove | 0:101a12a915c6 | 1 | /* mbed Example Program |
sam_grove | 0:101a12a915c6 | 2 | * Copyright (c) 2006-2014 ARM Limited |
sam_grove | 0:101a12a915c6 | 3 | * |
sam_grove | 0:101a12a915c6 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sam_grove | 0:101a12a915c6 | 5 | * you may not use this file except in compliance with the License. |
sam_grove | 0:101a12a915c6 | 6 | * You may obtain a copy of the License at |
sam_grove | 0:101a12a915c6 | 7 | * |
sam_grove | 0:101a12a915c6 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sam_grove | 0:101a12a915c6 | 9 | * |
sam_grove | 0:101a12a915c6 | 10 | * Unless required by applicable law or agreed to in writing, software |
sam_grove | 0:101a12a915c6 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
sam_grove | 0:101a12a915c6 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sam_grove | 0:101a12a915c6 | 13 | * See the License for the specific language governing permissions and |
sam_grove | 0:101a12a915c6 | 14 | * limitations under the License. |
sam_grove | 0:101a12a915c6 | 15 | */ |
sam_grove | 0:101a12a915c6 | 16 | |
jasonberry | 2:a6b6d93ff3cf | 17 | // Continuously sweep the servo through it's full range |
sam_grove | 0:101a12a915c6 | 18 | #include "mbed.h" |
jasonberry | 2:a6b6d93ff3cf | 19 | #include "Servo.h" |
sam_grove | 0:101a12a915c6 | 20 | |
jasonberry | 2:a6b6d93ff3cf | 21 | // Initialize a pins to perform SERIAL and digital output fucntions |
sam_grove | 0:101a12a915c6 | 22 | |
jasonberry | 2:a6b6d93ff3cf | 23 | DigitalOut dout(LED1); |
jasonberry | 2:a6b6d93ff3cf | 24 | Serial pc(USBTX, USBRX); // tx, rx |
jasonberry | 2:a6b6d93ff3cf | 25 | |
jasonberry | 2:a6b6d93ff3cf | 26 | |
jasonberry | 2:a6b6d93ff3cf | 27 | Servo myservo1(p21); |
jasonberry | 2:a6b6d93ff3cf | 28 | Servo myservo2(p22); |
jasonberry | 2:a6b6d93ff3cf | 29 | |
jasonberry | 2:a6b6d93ff3cf | 30 | int main() { |
jasonberry | 2:a6b6d93ff3cf | 31 | while(1) { |
jasonberry | 2:a6b6d93ff3cf | 32 | for(int i=0; i<100; i++) { |
jasonberry | 2:a6b6d93ff3cf | 33 | myservo1 = i/100.0; |
jasonberry | 2:a6b6d93ff3cf | 34 | myservo2 = i/100.0; |
jasonberry | 2:a6b6d93ff3cf | 35 | wait(0.01); |
jasonberry | 2:a6b6d93ff3cf | 36 | |
jasonberry | 2:a6b6d93ff3cf | 37 | } |
jasonberry | 2:a6b6d93ff3cf | 38 | for(int i=100; i>0; i--) { |
jasonberry | 2:a6b6d93ff3cf | 39 | myservo1 = i/100.0; |
jasonberry | 2:a6b6d93ff3cf | 40 | myservo2 = i/100.0; |
jasonberry | 2:a6b6d93ff3cf | 41 | wait(0.01); |
jasonberry | 2:a6b6d93ff3cf | 42 | |
jasonberry | 2:a6b6d93ff3cf | 43 | } |
jasonberry | 2:a6b6d93ff3cf | 44 | } |
jasonberry | 2:a6b6d93ff3cf | 45 | } |
jasonberry | 2:a6b6d93ff3cf | 46 |