Thiago .
/
OOP_Exercise
Conceito de Classe (Private Public),
Revision 2:f8dd6b50073a, committed 2015-08-04
- Comitter:
- Jamess
- Date:
- Tue Aug 04 14:14:54 2015 +0000
- Parent:
- 1:371785ebad41
- Commit message:
- Trabalhando com mais arquivos;
Changed in this revision
diff -r 371785ebad41 -r f8dd6b50073a Car.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Car.cpp Tue Aug 04 14:14:54 2015 +0000 @@ -0,0 +1,40 @@ +#include "Car.h" + +//Porque isso só deu certo aqui.? +//Quando eu colocava no car.h dava erro de multipla definição? + +DigitalOut turnRightLed(LED1); +DigitalOut turnLeftLed(LED2); + +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; + + } \ No newline at end of file
diff -r 371785ebad41 -r f8dd6b50073a Car.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Car.h Tue Aug 04 14:14:54 2015 +0000 @@ -0,0 +1,24 @@ +#ifndef CAR_MACRO_H +#define CAR_MACRO_H + +#include "mbed.h" + + + +class Car{ + + private: + uint32_t speed; + + public: + uint32_t getSpeed(void); + void setSpeed(uint32_t); + + void turnRight(void); + void turnLeft(void); + void goStraight(void); + + }; + + +#endif \ No newline at end of file
diff -r 371785ebad41 -r f8dd6b50073a main.cpp --- a/main.cpp Tue Aug 04 13:50:08 2015 +0000 +++ b/main.cpp Tue Aug 04 14:14:54 2015 +0000 @@ -1,46 +1,12 @@ //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); - - }; - +#include "Car.h" int main() { Car fusca; - MotorBike harley; - Car *foo; - foo = &fusca; - + while(1){ fusca.turnRight(); @@ -50,58 +16,8 @@ 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; - - } \ No newline at end of file