Advertisement
Guest User

Untitled

a guest
Jan 25th, 2013
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. #include "hardware.h"
  2.  
  3. // Initialise the hardware
  4. void appInitHardware(void) {
  5.     initHardware();
  6. }
  7. // Initialise the software
  8. TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
  9.     //PRINTF(stdout,"Ready..\r\n");
  10.  
  11.     display.print("2xPWM,2xSR04,4x20LCD");
  12.     display. setXY(0,1);
  13.     display.print("D0=    cm; D1=    cm");
  14.     display. setXY(0,2);
  15.     display.print("V0=    V ; V1=    V ");
  16.     display. setXY(0,3);
  17.     display.print("A0=    A ; A1=    A ");
  18.  
  19.     return 0;
  20. }
  21. // This is the main loop
  22. TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {
  23.  
  24.     {
  25.         // Read the Devantech SRF04 sonar and store the results
  26.         sonar0.read();
  27.         DISTANCE_TYPE cm = sonar0.getDistance();
  28.         display.setXY(4,1);
  29.         display.print(cm);
  30.         delay_ms(180); // freezes up without a delay
  31.     }
  32.     {
  33.         // Read the Devantech SRF04 sonar and store the results
  34.         sonar1.read();
  35.         DISTANCE_TYPE cm = sonar1.getDistance();
  36.         display.setXY(15,1);
  37.         display.print(cm);
  38.         delay_ms(180); // freezes up without a delay
  39.     }
  40.     {      
  41.         // Read the Analogue Input and store results
  42.         uint16_t val = a2dConvert10bit(adc0);
  43.         display.horizGraph(4,2,val,400,4);
  44.     }
  45.  
  46.     {      
  47.         // Read the Analogue Input and store results
  48.         uint16_t val = a2dConvert10bit(adc1);
  49.         display.horizGraph(4,3,val,40,4);
  50.     }
  51.  
  52.     {      
  53.         // Read the Analogue Input and store results
  54.         uint16_t val = a2dConvert10bit(adc2);
  55.         display.horizGraph(15,2,val,400,4);
  56.     }
  57.  
  58.     {      
  59.         // Read the Analogue Input and store results
  60.         uint16_t val = a2dConvert10bit(adc3);
  61.         display.horizGraph(15,3,val,40,4);
  62.     }
  63.  
  64.     // This example will move the motors back and forth using the loopStart time:
  65.     TICK_COUNT ms = loopStart / 1000;       // Get current time in ms
  66.     int16_t now = ms % (TICK_COUNT)10000;   // 10 sec for a full swing
  67.     if(now >= (int16_t)5000){               // Goes from 0ms...5000ms
  68.         now = (int16_t)10000 - now;         // then 5000ms...0ms
  69.     }
  70.     // Map it into DRIVE_SPEED range
  71.     DRIVE_SPEED speed = interpolate(now, 0, 5000, DRIVE_SPEED_MIN, DRIVE_SPEED_MAX);
  72.     // Set speed for all motors/servos
  73.     motor0.setSpeed(speed);
  74.     motor1.setSpeed(speed);
  75.     // -------- End   Actuators -------
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement