Presentation is loading. Please wait.

Presentation is loading. Please wait.

Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 1Winter Quarter Handy Board Lecture.

Similar presentations


Presentation on theme: "Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 1Winter Quarter Handy Board Lecture."— Presentation transcript:

1 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 1Winter Quarter Handy Board Lecture 26

2 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 2Winter Quarter Hands-on Lab #7 – The Traffic Light Hands-On Lab #7 will use the MIT Handy Board controller. First part of exercise is to write a C (not C++) program which performs functions to simulate the operation of a traffic light. Second part of exercise will be to convert program to run on Interactive C, the compiler for the Handy Board. Hand-outs will be provided for Handy Board basics, description of required C program, and laboratory exercise.

3 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 3Winter Quarter Programming in Real Time – Time of Day Programs which run in real time make frequent use of system timing functions and system clock. On the Unix system there are some useful timing routines in and We will need to use at least: –time defined in –sleepdefined in

4 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 4Winter Quarter Programming in Real Time – Time of Day From the time routine in we can look up the current time of day: NAME time - get time SYNOPSIS #include /* Not usually required */ #include time_t time (time_t *tloc) ; DESCRIPTION time returns the value of time in seconds since 00:00:00 UTC, January 1,1970. If tloc is non-zero, the return value is also stored in the location to which tloc points.

5 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 5Winter Quarter Programming in Real Time – Time of Day To get the elapsed time from some starting point: #include int time_start, time_now, delta_t ; … time_start = time (NULL) ; … time_now = time (NULL) ; delta_t = time_now - time_start ; More rigorously, one would probably use the difftime function: delta_t = difftime ( time_now, time_start) ;

6 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 6Winter Quarter A sleep function void sleep (float nseconds) { long start ; start = time (NULL) ; while (time (NULL) - start < nseconds) ; }

7 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 7Winter Quarter Programming in Real Time – Waiting From the sleep routine in we can wait for time to elapse (i.e., "take a nap"): NAME sleep - suspend execution for interval SYNOPSIS #include unsigned sleep (unsigned seconds); DESCRIPTION The current thread is suspended from execution for the number of seconds specified by the argument. The suspension time may be longer than requested by an arbitrary amount due to the scheduling of other activity in the system. See "man sleep" for more details on SLEEP(3C).

8 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 8Winter Quarter Programming in Real Time – Waiting To wait a specified amount of time between two statements in a program: #include int color1, color2, direction1, direction2;  change_lites (color1, direction1) ; sleep (6) ; change_lites (color2, direction2) ;

9 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 9Winter Quarter The Handy Board

10 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 10Winter Quarter The Handy Board The Handy Board features: 52–pin Motorola 6811 microprocessor with system clock at 2 MHz. 32K of battery-backed CMOS static RAM. Two L293D chips capable of driving four DC motors. 16 x 2 character LCD screen. Two user-programmable buttons, one knob, and piezo beeper. Powered header inputs for 7 analog sensors and 9 digital sensors. Internal 9.6v nicad battery with built-in recharging circuit. Hardware 38 kHz oscillator and drive transistor for IR output and on-board 38 kHz IR receiver. Board size of 4.25 x 3.15 inches, designed for a commercial, high grade plastic enclosure which holds battery pack beneath the board.

11 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 11Winter Quarter Interactive C Loosely based on ANSI C Several versions available: –IC version 3.2 - installed in lab, available for $35 per educational user from Newton Labs. This is the most up-to-date version for non-Expanded Handy Boards with some local (OSU) enhancements. –IC Version 4.2.x – also installed and will be used this quarter. May only be used with Expanded Handy Boards. –IC Version 8.0.2 – recently available and may be used next quarter. Available as a free download at http://www.botball.org/educational-resources/ic.php

12 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 12Winter Quarter Interactive C Things that are different in IC V3.2 (compared to ANSI C): –No function prototypes –No pointer arithmetic –Limited formats possible in printf –Array bounds checked at run time –Arrays can not be converted to pointers –No #include statements –Smaller set of allowable data types (only int, long, float, char, and struct –Character strings are supported, but simple char variables are not

13 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 13Winter Quarter Interactive C More things that are different in IC V3.2 (compared to ANSI C): –No switch/case construct –Can only do +, -, and * on long int ( No division) –All source files must be compiled together –No extern statement –#define has global scope –User functions come first in source file –No do/while construct

14 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 14Winter Quarter Traffic Light States

15 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 15Winter Quarter Traffic Light States

16 Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 16Winter Quarter Skeleton Program for Traffic Light void change ( /*parameters*/ ) { /* motor function calls (or display light status) */ } int main ( ) { /* declarations */ /* set initial light conditions */ /* while loop with timing and function calls */ }


Download ppt "Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 26P. 1Winter Quarter Handy Board Lecture."

Similar presentations


Ads by Google