fatboyslim / Mbed 2 deprecated buttontest

Dependencies:   FRDM-TFC mbed

main.cpp

Committer:
bbbobbbieo
Date:
2015-02-19
Revision:
7:455e7dd338ee
Parent:
6:44d1079f076c
Child:
8:946806df7347

File content as of revision 7:455e7dd338ee:

//#include "mbed.h"
#include "TFC.h"

DigitalOut myled(LED1);

int main() 
{
    //run this before anything
    TFC_Init();
    
    //variables
    float current_servo_position = 0;
    float current_left_motor_speed = 0;
    float current_right_motor_speed = 0;
    bool rear_motor_enable_flag = true;
    bool linescan_ping_pong = false;
    bool linescan_enable = false;
    
    uint16_t  MyImage0Buffer[2][128];
    uint16_t  MyImage1Buffer[2][128];
    
    
    // major loop
    while(1) 
    {
        
        if (TFC_ReadPushButton(0) != 0 )
            {
                TFC_BAT_LED0_ON;
                wait(0.004);
                TFC_BAT_LED0_OFF; 
                wait(0.004);
                
                current_servo_position = current_servo_position-.005;
                if(current_servo_position <= -0.4)
                    current_servo_position = -0.4;
                TFC_SetServo(0, current_servo_position);
            }// end check button0
            
        else
            {
                TFC_BAT_LED0_ON;
            }
            
        if (TFC_ReadPushButton(1) != 0 )
            {
                TFC_BAT_LED1_ON;
                wait(0.004);
                TFC_BAT_LED1_OFF; 
                wait(0.004);
                
                current_servo_position = current_servo_position+.005;
                if(current_servo_position >= 0.4)
                    current_servo_position = 0.4;
                TFC_SetServo(0, current_servo_position);
            }// end check button1
            
        else
            {
                TFC_BAT_LED1_ON;
            }
            
        if(rear_motor_enable_flag)
            {
                TFC_HBRIDGE_ENABLE;
                //current_left_motor_speed    = current_left_motor_speed +  .3*(TFC_ReadPot(0));
                //current_right_motor_speed   = current_right_motor_speed +  .3*(TFC_ReadPot(1));
                
                //current_left_motor_speed    = .3*(TFC_ReadPot(0));
                //current_right_motor_speed   = .3*(TFC_ReadPot(1));
                
                current_left_motor_speed    = (TFC_ReadPot(0));
                current_right_motor_speed   = (TFC_ReadPot(1));
                
                if(current_left_motor_speed >= 0.4)
                    current_left_motor_speed= 0.4;
                if(current_right_motor_speed >= 0.4)
                    current_right_motor_speed= 0.4;    
                if(current_left_motor_speed <= -0.4)
                    current_left_motor_speed= -0.4;
                if(current_right_motor_speed <= -0.4)
                    current_right_motor_speed= -0.4;                       
                    
                TFC_SetMotorPWM(current_left_motor_speed, current_right_motor_speed);
            }// end motor enabled
        else
            {
                TFC_HBRIDGE_DISABLE;
            }// end motor disabled    
       
        if (linescan_enable)
            {
             if (TFC_LineScanImageReady !=0)
                {
                if (linescan_ping_pong) //checking channel 0
                    {
                        //...
                        linescan_ping_pong = false;
                    }
                else                    //checking channel 1
                    {
                        //...
                        linescan_ping_pong = true;
                    }
                    
                TFC_LineScanImageReady ==0;  // since we used it, we reset the flag
                }// end imageready
            }// end linescan stuff     
    }
}
//hi guys