Download
the george washington university department of ece ece 1010 intro electrical computer engineering n.
Skip this Video
Loading SlideShow in 5 Seconds..
Dr. S. Ahmadi Class 4 PowerPoint Presentation
Download Presentation
Dr. S. Ahmadi Class 4

Dr. S. Ahmadi Class 4

1 Views Download Presentation
Download Presentation

Dr. S. Ahmadi Class 4

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. The George Washington University Department of ECE ECE 1010 - 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 functiondigital(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 1, @ 3% of speed. motor (3,70); // Turn on motor 3, @ 3% of speed. if ( digital(13)==1 ) // Check sensor connected to port { motor (1, -70); // Turn on motor 1, @ 3% of speed in opposite direction. motor (3, -70); // Turn on motor 1, @ 3% of speed in opposite direction. sleep(4); } return 0 }

  7. Classwork • AA1FB int main() { fd(0); fd(2); sleep(3); bk(0); bk(2); sleep(3); 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(){ intcolor_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(){ intcolor_threshold = 200; while(1){ 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(){ intcolor_threshold = 200; 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; }