Download presentation
Presentation is loading. Please wait.
Published byAnissa Thompson Modified over 5 years ago
1
The George Washington University Department of ECE ECE Intro: Electrical & Computer Engineering Dr. S. Ahmadi Class 4
2
Touch Sensors Is a type of digital sensor: - Returns a 0 if NOT hit
- Returns a 1 if HIT - As with any digital sensor, it is either “ON” or “OFF” - Digital sensors connect to digital ports (7-15) on the “lower deck” of the handyboard (see diagram of the handyboard on the next slide)
3
Digital Ports
4
Touch Sensor Digital sensor
Connect to digital ports 8-15 on the KIPR Link Access with function digital(port#) 1 indicates switch is closed 0 indicates switch is open
5
Utilizing the touch sensor to help robot turn intelligently
Write an IC program that does the following: runs forward for an unspecified amount of time detects a “hit” using a digital sensor attached to the front of the robot and then backs up (for x seconds --- you decide what number is best for x – HINT use a variable!) Download and run
6
Simple Example To Use Bumpers
// Program to make a robot go forward. // If hit detected, go backwards for 4 seconds. int main() { while( a_button()==0 ){ } // Waits for user to press start button. while(1) motor (1,70); // Turn on motor 3% of speed. motor (3,70); // Turn on motor 3% of speed. if ( digital(13)==1 ) // Check sensor connected to port motor (1, -70); // Turn on motor 3% of speed in opposite direction. motor (3, -70); // Turn on motor 3% of speed in opposite direction. sleep(4); } return 0
7
Classwork AA1FB int main() { } fd(2); sleep(3); bk(0); bk(2); ao();
8
Classwork AA2Sen int main(){ while(1){
printf("Sensor reading : %d\n", analog10(0)); msleep(500); } return 0;
9
Classwork AA3FSenB_once int main(){ bk(0); bk(2);
int color_threshold = 200; while(1){ if(analog10(0) > color_threshold && analog10(1) > color_threshold) break; fd(0); fd(2); msleep(100); } bk(0); bk(2); sleep(2); ao(); return 0; }
10
Classwork AA4FSenB_loop int main(){ int color_threshold = 200; bk(0);
while(1){ if(analog10(0) > color_threshold && analog10(1) > color_threshold) break; fd(0); fd(2); msleep(100); } bk(0); bk(2); sleep(2); ao(); msleep(100); } return 0;
11
Classwork AA5SenB_three int main(){ int color_threshold = 200; bk(0);
int n = 1; while(n <= 3){ while(1){ if(analog10(0) > color_threshold && analog10(1) > color_threshold) break; fd(0); fd(2); msleep(100); } bk(0); bk(2); sleep(2); ao(); n = n+1; msleep(100); } return 0;
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.