LOJA FÍSICA
Praça Mauá, 4541 - Sala 22
09580-050 - São Caetano do Sul / SP
CENTRAL DE ATENDIMENTO
(11) 3522-7626
info@robocore.net
HORÁRIO DE FUNCIONAMENTO
De segunda à sexta das 9:00 às 19:00
Retornar
ao topo

Classifique este tópicoPéssimoRuimMedianoBomÓtimo
Autor
Mensagem
3
luan_h_nogueira

Level 0
0 xp

Registrado em:
29/07/2018





Mensagens:
1
3
luan_h_nogueira

Responder com citações
Mensagem Dom Jul 29, 2018 7:16 pm
ALGUEM ME AJUDA A ACHAR O CONFLITO DO PINO 4 ?!
ESSE É O SKECTH, TEM UM CONFLITO NO PINO 4 E ELE NAO FUNCIONA E ATÉ AGR NAO CONSEGUI RESOLVER O PROBLEMA !! ALGUEM ME AJUDA




#include <Servo.h>

const int SPEEDO_PIN      = A0;
const int RPM_PIN         = A1;
const int FUEL_PIN        = A5;
const int LEFT_INDICATOR  = A2;
const int RIGHT_INDICATOR = A3;
const int PARKING_BREAK   = A4;
const int CRUISE_CONTROL  = 11;
const int FUEL_WARNING    = 12;
const int LOW_BEAM        = 0;
const int HIGH_BEAM       = 13;

int pinA = 9;
int pinB = 8;
int pinC = 7;
int pinD = 6;
int pinE = 5;
int pinF = 10;
int pinG = 3;
int pinH = 2;

// defines servo names
Servo speedo;
Servo rpm;
Servo fuel;
Servo cruise;

#define PACKET_SYNC 0xFF
#define PACKET_VER  2

#define SERVO_DIR_NORMAL false
#define SERVO_DIR_INVERT true

int serial_byte;

void setup()
{
  Serial.begin(115200);

  speedo.attach(SPEEDO_PIN);
  speedo.write(180);
  rpm.attach(RPM_PIN);
  rpm.write(180);
  fuel.attach(FUEL_PIN);
  fuel.write(170);
  cruise.write(180);

  pinMode(LEFT_INDICATOR, OUTPUT);
  pinMode(RIGHT_INDICATOR, OUTPUT);
  pinMode(PARKING_BREAK, OUTPUT);
  pinMode(FUEL_WARNING, OUTPUT);
  pinMode(CRUISE_CONTROL, OUTPUT);
  pinMode(LOW_BEAM, OUTPUT);
  pinMode(HIGH_BEAM, OUTPUT);
  pinMode(pinA, OUTPUT);
  pinMode(pinB, OUTPUT);
  pinMode(pinC, OUTPUT);
  pinMode(pinD, OUTPUT);
  pinMode(pinE, OUTPUT);
  pinMode(pinF, OUTPUT);
  pinMode(pinG, OUTPUT);
  pinMode(pinH, OUTPUT);

  //range-splitter LED's
  pinMode(22, OUTPUT);
  pinMode(24, OUTPUT);
  pinMode(26, OUTPUT);

  digitalWrite(LEFT_INDICATOR, 0);
  digitalWrite(RIGHT_INDICATOR, 0);
  digitalWrite(PARKING_BREAK, 0);
  digitalWrite(FUEL_WARNING, 0);
  digitalWrite(CRUISE_CONTROL, 0);
  digitalWrite(LOW_BEAM, 0);
  digitalWrite(HIGH_BEAM, 0);

  delay(500);

  speedo.write(0);
  rpm.write(0);
  fuel.write(0);
  digitalWrite(LEFT_INDICATOR, 1);
  digitalWrite(RIGHT_INDICATOR, 1);
  digitalWrite(PARKING_BREAK, 1);
  digitalWrite(FUEL_WARNING, 1);
  digitalWrite(CRUISE_CONTROL, 1);
  digitalWrite(LOW_BEAM, 1);
  digitalWrite(HIGH_BEAM, 1);
  digitalWrite(22, 1);
  digitalWrite(24, 1);
  digitalWrite(26, 1);

  delay(500);

  speedo.write(180);
  rpm.write(180);
  fuel.write(170);
  digitalWrite(LEFT_INDICATOR, 0);
  digitalWrite(RIGHT_INDICATOR, 0);
  digitalWrite(PARKING_BREAK, 0);
  digitalWrite(FUEL_WARNING, 0);
  digitalWrite(CRUISE_CONTROL, 0);
  digitalWrite(LOW_BEAM, 0);
  digitalWrite(HIGH_BEAM, 0);
  digitalWrite(22, 0);
  digitalWrite(24, 0);
  digitalWrite(26, 0);

  digitalWrite(pinA, HIGH);
  digitalWrite(pinB, HIGH);
  digitalWrite(pinC, HIGH);
  digitalWrite(pinD, HIGH);
  digitalWrite(pinE, HIGH);
  digitalWrite(pinF, HIGH);
  digitalWrite(pinG, HIGH);
  digitalWrite(pinH, HIGH);

  delay(1000);
}

void read_serial_byte_set_servo(Servo& servo, bool invert)
{
  serial_byte = Serial.read();
  serial_byte = (serial_byte < 0) ? 0 : ((serial_byte > 180) ? 180 : serial_byte);
  if (invert)
    servo.write(180 - serial_byte);
  else
    servo.write(serial_byte);
}

void read_serial_byte_set_servo_fuel(Servo& servo, bool invert)
{
  serial_byte = Serial.read();
  serial_byte = (serial_byte < 0) ? 0 : ((serial_byte > 180) ? 180 : serial_byte);
  if (invert)
    servo.write(170 - serial_byte); //set lower than the tach and speedo to limit movement.
  else
    servo.write(serial_byte);
}

void read_serial_byte_set_servo_cruise(Servo& servo, bool invert)
{
  serial_byte = Serial.read();
  serial_byte = (serial_byte < 0) ? 0 : ((serial_byte > 180) ? 180 : serial_byte);
  if (invert)
    servo.write(180 - serial_byte); //set lower than the tach and speedo to limit movement.
  else
    servo.write(serial_byte);
}

void skip_serial_byte()
{
  (void)Serial.read();
}

void digitalWriteFromBit(int port, int value, int shift)
{
  digitalWrite(port, (value >> shift) & 0x01);
}

void loop()
{
  if (Serial.available() < 16)
    return;

  serial_byte = Serial.read();
  if (serial_byte != PACKET_SYNC)
    return;

  serial_byte = Serial.read();
  if (serial_byte != PACKET_VER)
  {
    //    lcd.clear();
    //   lcd.print("PROTOCOL VERSION ERROR");
    return;
  }

  read_serial_byte_set_servo(speedo, SERVO_DIR_INVERT); // Speed
  read_serial_byte_set_servo(rpm, SERVO_DIR_INVERT); // RPM
  
 
  skip_serial_byte(); // Brake air pressure
  skip_serial_byte(); // Brake temperature
  read_serial_byte_set_servo_fuel(fuel, SERVO_DIR_NORMAL); // Fuel ratio
  skip_serial_byte(); // Oil pressure
  skip_serial_byte(); // Oil temperature
  skip_serial_byte(); // Water temperature
  skip_serial_byte(); // Battery voltage
  read_serial_byte_set_servo_cruise(cruise, SERVO_DIR_INVERT); // cruise speed, set to trip a light
 

  if (cruise.read() < 180)
  {
    digitalWrite(CRUISE_CONTROL, 1);
  }
  if (cruise.read() > 179)
  {
    digitalWrite(CRUISE_CONTROL, 0);
  }

  // Truck lights byte
  serial_byte = Serial.read();
  digitalWriteFromBit(LEFT_INDICATOR,  serial_byte, 5);
  digitalWriteFromBit(RIGHT_INDICATOR, serial_byte, 4);
  digitalWriteFromBit(LOW_BEAM,  serial_byte, 3);
  digitalWriteFromBit(HIGH_BEAM, serial_byte, 2);


  // Warning lights bytes

  serial_byte = Serial.read();
  digitalWriteFromBit(PARKING_BREAK, serial_byte, 7);
  digitalWriteFromBit(FUEL_WARNING, serial_byte, 3);

  // Enabled flags
  serial_byte = Serial.read();

  // Text length
  int text_len = Serial.read();

  // Followed by text
  if (0 < text_len && text_len < 127)
  {
    for (int i = 0; i < text_len; ++i)
    {

      while (Serial.available() == 0) // Wait for data if slow
      {
        delay(2);
      }
      serial_byte = Serial.read();
      if (serial_byte == 'a')
      {
        //1
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, LOW);
        digitalWrite(pinH, LOW);
      }
      else  if (serial_byte == 'b')
      {
        //2
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, HIGH);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, LOW);
      }
      else  if (serial_byte == 'c')
      {
        //3
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, LOW);
      }
      else  if (serial_byte == 'd')
      {
        //4
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, HIGH);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, LOW);
      }
      else  if (serial_byte == 'e')
      {
        //5
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, HIGH);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, LOW);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, LOW);
      }
      else  if (serial_byte == 'f')
      {
        //6
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, HIGH);
        digitalWrite(pinC, HIGH);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, LOW);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, LOW);
      }
      else  if (serial_byte == 'g')
      {
        //7
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, LOW);
        digitalWrite(pinH, LOW);
      }
      else  if (serial_byte == 'h')
      {
        //8
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, HIGH);
        digitalWrite(pinC, HIGH);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, LOW);
      }
      else  if (serial_byte == 'i')
      {
        //9
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, HIGH);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, LOW);
      }
      else  if (serial_byte == 'j')
      {
        //10
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, HIGH);
        digitalWrite(pinC, HIGH);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, LOW);
        digitalWrite(pinH, HIGH);
      }
      else  if (serial_byte == 'k')
      {
        //11
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, LOW);
        digitalWrite(pinH, HIGH);
      }
      else  if (serial_byte == 'l')
      {
        //12
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, HIGH);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, HIGH);
      }
      else  if (serial_byte == 'm')
      {
        //13
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, HIGH);
      }
      else  if (serial_byte == 'n')
      {
        //14
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, HIGH);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, HIGH);
      }
      else  if (serial_byte == 'o')
      {
        //15
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, HIGH);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, LOW);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, HIGH);
      }
      else  if (serial_byte == 'p')
      {
        //16
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, HIGH);
        digitalWrite(pinC, HIGH);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, LOW);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, HIGH);
      }
      else  if (serial_byte == 'q')
      {
        //17
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, LOW);
        digitalWrite(pinH, HIGH);
      }
      else  if (serial_byte == 'r')
      {
        //18
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, HIGH);
        digitalWrite(pinC, HIGH);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, HIGH);
      }
      else  if (serial_byte == 's')
      {
        // R1
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, LOW);
        digitalWrite(pinH, LOW);
      }
      else  if (serial_byte == 't')
      {
        //R2
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, HIGH);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, LOW);
      }
      else  if (serial_byte == 'u')
      {
        //R3
        digitalWrite(pinA, HIGH);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, HIGH);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, LOW);
      }
      else  if (serial_byte == 'v')
      {
        //R4
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, HIGH);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, HIGH);
        digitalWrite(pinF, HIGH);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, LOW);
      }
      else  if (serial_byte == 'w')
      {
        // Neutral
        digitalWrite(pinA, LOW);
        digitalWrite(pinB, LOW);
        digitalWrite(pinC, LOW);
        digitalWrite(pinD, LOW);
        digitalWrite(pinE, LOW);
        digitalWrite(pinF, LOW);
        digitalWrite(pinG, HIGH);
        digitalWrite(pinH, LOW);
      }
      //sets range splitter LED's
      if (serial_byte == 'a' || serial_byte == 'd' || serial_byte == 'g' || serial_byte == 'j' || serial_byte == 'm' || serial_byte == 'p' || serial_byte == 's' || serial_byte == 'v')
      {
        digitalWrite(22, 1);
      }
      else
      {
        digitalWrite(22, 0);
      }
      if (serial_byte == 'b' || serial_byte == 'e' || serial_byte == 'h' || serial_byte == 'k' || serial_byte == 'n' || serial_byte == 'q' || serial_byte == 't')
      {
        digitalWrite(24, 1);
      }
      else
      {
        digitalWrite(24, 0);
      }
      if (serial_byte == 'c' || serial_byte == 'f' || serial_byte == 'i' || serial_byte == 'l' || serial_byte == 'o' || serial_byte == 'r' || serial_byte == 'u')
      {
        digitalWrite(26, 1);
      }
      else
      {
        digitalWrite(26, 0);
      }

    }
  }
}
Mostrar mensagens desde a última:




Ir para:  
Todos os horários são GMT - 3 HorasVocê não tem permissão para escrever novas mensagens
v não tem permissão para responder às mensagens
Você não tem permissão para editar suas mensagens
Você não tem permissão para deletar suas mensagens
Você não tem permissão para classificar tópicos
Você não tem permissão para classificar mensagens
Você não tem permissão para votar em enquetes
Anexar downloads : Proibido
Fazer Download de Arquivos: Proibido
Powered by phpBB © 2001 phpBB Group