Conceito de Classe (Private Public),

Dependencies:   mbed

main.cpp

Committer:
Jamess
Date:
2015-08-04
Revision:
1:371785ebad41
Parent:
0:183b60b46e25
Child:
2:f8dd6b50073a

File content as of revision 1:371785ebad41:

//Pointer to Classes

#include "mbed.h"

DigitalOut turnRightLed(LED1);
DigitalOut turnLeftLed(LED3);

class Car{
      
    private:
        uint32_t speed;
        
    public:
        uint32_t getSpeed(void);
        void setSpeed(uint32_t);
        
        void turnRight(void);
        void turnLeft(void);
        void goStraight(void);
    
    };
    
class MotorBike{  
    
    private:
        
    uint32_t speed;
    
    public:
    
    void setSpeed(uint32_t);
    uint32_t getSpeed(void);
    
    };
        

int main() {
    
    Car fusca;
    MotorBike harley;
    Car *foo;
    foo = &fusca;
    
    while(1){
        
        fusca.turnRight();
        wait(1);
        fusca.goStraight();
        wait(1);
        fusca.turnLeft();
        wait(2);
        
        foo->turnRight();
        wait(1);
        foo->turnLeft();
        wait(1);
        
        }

}

/*---------FUNCTION----------*/

void Car::turnRight(void){
    
    turnRightLed = 0;
    turnLeftLed = 1;    
    
    }
    
void Car::turnLeft(void){
    
    turnRightLed = 1;
    turnLeftLed = 0;    
    
    }

void Car::goStraight(void){
    
    turnRightLed = 1;
    turnLeftLed = 1;
    
    }

uint32_t Car::getSpeed(void){
    
    return speed;
    
    }

void Car::setSpeed(uint32_t value1){
    
    speed = value1;
    
    }

void MotorBike::setSpeed(uint32_t value2){
    
    speed = value2;
    
    }

uint32_t MotorBike::getSpeed(void){
    
    return speed;
    
    }