Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<UnicViewAD.h>
- #include<Servo.h>
- LCM Lcm(Serial);
- Servo ServoMotor;
- /***********************************************************************/
- /***********************************************************************/
- const int ledPinRed = 2;
- const int ledPinGreen = 3;
- const int ledPinBlue = 4;
- const int ledOn = 1;
- const int ledOff = 0;
- const int ledsOff[] = {LOW, LOW, LOW};
- const int ledRedOnly[] = {HIGH, LOW, LOW};
- const int ledGreenOnly[] = {LOW, HIGH, LOW};
- const int ledBlueOnly[] = {LOW, LOW, HIGH};
- const int ledPurpleOnly[] = {HIGH, HIGH, LOW};
- const int ledCyanOnly[] = {LOW, HIGH, HIGH};
- const int ledYellowOnly[] = {HIGH, HIGH, LOW};
- const int colorsDisplayOff[] = {0, 0, 0, 0, 0, 0};
- const int colorsDisplayRed[] = {1, 0, 0, 0, 0, 0};
- const int colorsDisplayGreen[] = {0, 1, 0, 0, 0, 0};
- const int colorsDisplayBlue[] = {0, 0, 1, 0, 0, 0};
- const int colorsDisplayPurple[] = {1, 0, 1, 1, 0, 0};
- const int colorsDisplayCyan[] = {0, 1, 1, 0, 1, 0};
- const int colorsDisplayYellow[] = {1, 1, 0, 0, 0, 1};
- LcmVar ledButtonRed(15);
- LcmVar ledButtonGreen(16);
- LcmVar ledButtonBlue(17);
- LcmVar ledButtonPurple(18);
- LcmVar ledButtonCyan(19);
- LcmVar ledButtonYellow(20);
- /***********************************************************************/
- const int servoPin = 9;
- int positionCurrent = 0;
- int tempB = 0;
- bool updatePosition = true;
- long int nextPosition = 0;
- const int nextWriteIntervalInMs = 20;
- LcmVar temperatureButton(1000);
- LcmVar temperatura(1001);
- void setup()
- {
- Lcm.begin(115200);
- pinMode(ledPinRed, OUTPUT);
- pinMode(ledPinGreen, OUTPUT);
- pinMode(ledPinBlue, OUTPUT);
- ServoMotor.attach(servoPin);
- ServoMotor.write(20);
- pinMode(servoPin, OUTPUT);
- }
- void loop()
- {
- //MOTOR
- if(temperatureButton.available())
- {
- tempB = temperatureButton.getData();
- updatePosition = true;
- }
- if (updatePosition == true)
- {
- if (millis() > nextPosition)
- {
- if (tempB > positionCurrent)
- {
- positionCurrent++;
- }
- else if (tempB < positionCurrent)
- {
- positionCurrent--;
- }
- ServoMotor.write(positionCurrent);
- temperatura.write(positionCurrent);
- nextPosition = millis() + nextWriteIntervalInMs;
- }
- }
- if(tempB == positionCurrent)
- {
- updatePosition = false;
- }
- /************************************************************************/
- //LEDS
- if(ledButtonRed.available())
- {
- int led_estadoRed = ledButtonRed.getData();
- if(led_estadoRed == ledOn)
- {
- Update(ledRedOnly, colorsDisplayRed);
- }
- if(led_estadoRed == ledOff)
- {
- Update(ledsOff, colorsDisplayOff);
- }
- }
- if(ledButtonGreen.available())
- {
- int led_estadoGreen = ledButtonGreen.getData();
- if(led_estadoGreen == ledOn)
- {
- Update(ledGreenOnly, colorsDisplayGreen);
- }
- if(led_estadoGreen == ledOff)
- {
- Update(ledsOff, colorsDisplayOff);
- }
- }
- if(ledButtonBlue.available())
- {
- int led_estadoBlue = ledButtonBlue.getData();
- if(led_estadoBlue == ledOn)
- {
- Update(ledBlueOnly, colorsDisplayBlue);
- }
- if(led_estadoBlue == ledOff)
- {
- Update(ledsOff, colorsDisplayOff);
- }
- }
- if(ledButtonPurple.available())
- {
- int led_estadoPurple = ledButtonPurple.getData();
- if(led_estadoPurple == ledOn)
- {
- Update(ledPurpleOnly, colorsDisplayPurple);
- }
- if(led_estadoPurple == ledOff)
- {
- Update(ledsOff, colorsDisplayOff);
- }
- }
- if(ledButtonCyan.available())
- {
- int led_estadoCyan = ledButtonCyan.getData();
- if(led_estadoCyan == ledOn)
- {
- Update(ledCyanOnly, colorsDisplayCyan);
- }
- if(led_estadoCyan == ledOff)
- {
- Update(ledsOff, colorsDisplayOff);
- }
- }
- if(ledButtonYellow.available())
- {
- int led_estadoYellow = ledButtonYellow.getData();
- if(led_estadoYellow == ledOn)
- {
- Update(ledYellowOnly, colorsDisplayYellow);
- }
- if(led_estadoYellow == ledOff)
- {
- Update(ledsOff, colorsDisplayOff);
- }
- }
- }
- void Update(int ledState[], int colorsDisplay[])
- {
- EstadoLed(ledState);
- AtualizarDisplay(colorsDisplay);
- }
- void EstadoLed(int ledState[])
- {
- digitalWrite(ledPinRed, ledState[0]);
- digitalWrite(ledPinGreen, ledState[1]);
- digitalWrite(ledPinBlue, ledState[2]);
- }
- void AtualizarDisplay(int colorsDisplay[])
- {
- ledButtonRed.write(colorsDisplay[0]);
- ledButtonGreen.write(colorsDisplay[1]);
- ledButtonBlue.write(colorsDisplay[2]);
- ledButtonPurple.write(colorsDisplay[3]);
- ledButtonCyan.write(colorsDisplay[4]);
- ledButtonYellow.write(colorsDisplay[5]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement