SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   // Library Area
  2.   #include <IFCT.h>
  3.   #include <SPI.h>
  4.  
  5.   const int can0_enable = 2;  // defines can0 enable pin, pin 28, as can0_enable
  6.   CAN_message_t msg;
  7.    
  8.   // Setup Area
  9.   const int SOL1 = 32;
  10.   const int SOL2 = 31;
  11.   const int SOL3 = 30;
  12.   const int SOL4 = 29;
  13.   const int SOL5 = 25;
  14.   const int SOL6 = 26;
  15.   const int SOL7 = 27;
  16.   const int SOL8 = 28;
  17.   const int L01 = 5;
  18.   const int L02 = 6;
  19.   const int L03 = 7;
  20.   const int L04 = 8;
  21.   const int L05 = 9;
  22.   const int L06 = 10;
  23.   const int L07 = 11;
  24.   const int L08 = 12;
  25.   const int btn01 = 16;
  26.   const int btn02 = 15;
  27.   const int btn03 = 14;
  28.   const int btn04 = 13;
  29.   const int btn05 = 20;
  30.   const int btn06 = 19;
  31.   const int btn07 = 18;
  32.   const int btn08 = 17;
  33.   byte btnhold = 0;
  34.   byte shift = 0;
  35.   byte neutral = 0;
  36.   byte reverse = 0;
  37.   byte gear = 0;
  38.   byte delay12 = 0;
  39.   byte delay23 = 0;
  40.   byte delay34 = 0;
  41.   byte delay45 = 0;
  42.   byte delay56 = 0;
  43.   byte delay67 = 0;
  44.   byte btnStatus01 = 0;
  45.   byte btnStatus02 = 0;
  46.   byte btnStatus03 = 0;
  47.   byte btnStatus04 = 0;
  48.   byte btnStatus05 = 0;
  49.   byte btnStatus06 = 0;
  50.   byte btnStatus07 = 0;
  51.   byte btnStatus08 = 0;
  52.   byte outStatus01 = 0;
  53.   byte outStatus02 = 0;
  54.   byte outStatus03 = 0;
  55.   byte outStatus04 = 0;
  56.   byte outStatus05 = 0;
  57.   byte outStatus06 = 0;
  58.   byte outStatus07 = 0;
  59.   byte outStatus08 = 0;
  60.   elapsedMillis timer1;
  61.  
  62.   void setup() {
  63.     // put your setup code here, to run once:
  64.     pinMode(SOL1, OUTPUT);
  65.     pinMode(SOL2, OUTPUT);
  66.     pinMode(SOL3, OUTPUT);
  67.     pinMode(SOL4, OUTPUT);
  68.     pinMode(SOL5, OUTPUT);
  69.     pinMode(SOL6, OUTPUT);
  70.     pinMode(SOL7, OUTPUT);
  71.     pinMode(SOL8, OUTPUT);
  72.     pinMode(L01, OUTPUT);
  73.     pinMode(L02, OUTPUT);
  74.     pinMode(L03, OUTPUT);
  75.     pinMode(L04, OUTPUT);
  76.     pinMode(L05, OUTPUT);
  77.     pinMode(L06, OUTPUT);
  78.     pinMode(L07, OUTPUT);
  79.     pinMode(L08, OUTPUT);
  80.     pinMode(btn01, INPUT);
  81.     pinMode(btn02, INPUT);
  82.     pinMode(btn03, INPUT);
  83.     pinMode(btn04, INPUT);
  84.     pinMode(btn05, INPUT);
  85.     pinMode(btn06, INPUT);
  86.     pinMode(btn07, INPUT);
  87.     pinMode(btn08, INPUT);
  88.     digitalWrite(SOL1, HIGH);
  89.     digitalWrite(SOL2, HIGH);
  90.     digitalWrite(SOL3, HIGH);
  91.     digitalWrite(SOL4, HIGH);
  92.     digitalWrite(SOL5, HIGH);
  93.     digitalWrite(SOL6, HIGH);
  94.     digitalWrite(SOL7, HIGH);
  95.     digitalWrite(SOL8, HIGH);
  96.     digitalWrite(L01, HIGH);
  97.     digitalWrite(L02, HIGH);
  98.     digitalWrite(L03, HIGH);
  99.     digitalWrite(L04, HIGH);
  100.     digitalWrite(L05, HIGH);
  101.     digitalWrite(L06, HIGH);
  102.     digitalWrite(L07, HIGH);
  103.     digitalWrite(L08, HIGH);
  104.     digitalWrite(24, LOW);
  105.     Serial.begin(115200);
  106.     pinMode(can0_enable, OUTPUT);  // for the can0 transceiver enable pin
  107.     digitalWrite(can0_enable, LOW);  // can0 enable pin needs to be low to receive messages
  108.     Can0.setBaudRate(1000000); // Canbus 0 Bitrate in bits per second.
  109.     Can0.enableFIFO();
  110.     Can0.enableFIFOInterrupt();
  111.     Can0.intervalTimer(); // enable queue system and run callback in background.
  112.     Can0.onReceive(canSniff0);
  113.   }
  114.  
  115.   void loop() {
  116.     // Integer Read Loop
  117.     if (timer1 >= 10) {
  118.     if ( (digitalRead(btn08) == LOW) && (btnhold == 0) ) {
  119.       Serial.println(F("Shift Command Received..."));
  120.       btnhold = 1;
  121.       btnStatus08 = 1;
  122.       shift = (shift + 1) % 6 ;
  123.  
  124.       switch (shift) {
  125.         case 0:    //
  126.           digitalWrite(SOL1, HIGH);
  127.           outStatus01 = 0;
  128.           digitalWrite(SOL2, HIGH);
  129.           outStatus02 = 0;
  130.           digitalWrite(SOL3, HIGH);
  131.           outStatus03 = 0;
  132.           digitalWrite(SOL4, HIGH);
  133.           outStatus04 = 0;
  134.           digitalWrite(SOL5, HIGH);
  135.           outStatus05 = 0;
  136.           digitalWrite(L01, HIGH);
  137.           digitalWrite(L02, HIGH);
  138.           digitalWrite(L03, HIGH);
  139.           digitalWrite(L04, HIGH);
  140.           digitalWrite(L05, HIGH);
  141.           Serial.println(F("GEAR N"));
  142.           gear = 0;
  143.  
  144.           break;
  145.  
  146.         case 1:    //
  147.           digitalWrite(SOL1, LOW);
  148.           outStatus01 = 1;
  149.           digitalWrite(SOL2, HIGH);
  150.           outStatus02 = 0;
  151.           digitalWrite(SOL3, HIGH);
  152.           outStatus03 = 0;
  153.           digitalWrite(SOL4, HIGH);
  154.           outStatus04 = 0;
  155.           digitalWrite(SOL5, HIGH);
  156.           outStatus05 = 0;
  157.           digitalWrite(L01, LOW);
  158.           digitalWrite(L02, HIGH);
  159.           digitalWrite(L03, HIGH);
  160.           digitalWrite(L04, HIGH);
  161.           digitalWrite(L05, HIGH);
  162.           Serial.println(F("GEAR 1"));
  163.           gear = 1;
  164.           break;
  165.  
  166.         case 2:    //
  167.           digitalWrite(SOL1, HIGH);
  168.           outStatus01 = 0;
  169.           delay(delay12);
  170.           digitalWrite(SOL2, LOW);
  171.           outStatus02 = 1;
  172.           digitalWrite(SOL3, HIGH);
  173.           outStatus03 = 0;
  174.           digitalWrite(SOL4, HIGH);
  175.           outStatus04 = 0;
  176.           digitalWrite(SOL5, HIGH);
  177.           outStatus05 = 0;
  178.           digitalWrite(L01, HIGH);
  179.           digitalWrite(L02, LOW);
  180.           digitalWrite(L03, HIGH);
  181.           digitalWrite(L04, HIGH);
  182.           digitalWrite(L05, HIGH);
  183.           Serial.println(F("GEAR 2"));
  184.           gear = 2;
  185.           break;
  186.  
  187.         case 3:    //
  188.           digitalWrite(SOL1, HIGH);
  189.           outStatus01 = 0;
  190.           digitalWrite(SOL2, HIGH);
  191.           outStatus02 = 0;
  192.           delay(delay23);
  193.           digitalWrite(SOL3, LOW);
  194.           outStatus03 = 1;
  195.           digitalWrite(SOL4, HIGH);
  196.           outStatus04 = 0;
  197.           digitalWrite(SOL5, HIGH);
  198.           outStatus05 = 0;
  199.           digitalWrite(L01, HIGH);
  200.           digitalWrite(L02, HIGH);
  201.           digitalWrite(L03, LOW);
  202.           digitalWrite(L04, HIGH);
  203.           digitalWrite(L05, HIGH);
  204.           Serial.println(F("GEAR 3"));
  205.           gear = 3;
  206.           break;
  207.  
  208.         case 4:    //
  209.           digitalWrite(SOL1, HIGH);
  210.           outStatus01 = 0;
  211.           digitalWrite(SOL2, HIGH);
  212.           outStatus02 = 0;
  213.           digitalWrite(SOL3, HIGH);
  214.           outStatus03 = 0;
  215.           delay(delay34);
  216.           digitalWrite(SOL4, LOW);
  217.           outStatus04 = 1;
  218.           digitalWrite(SOL5, HIGH);
  219.           outStatus05 = 0;
  220.           digitalWrite(L01, HIGH);
  221.           digitalWrite(L02, HIGH);
  222.           digitalWrite(L03, HIGH);
  223.           digitalWrite(L04, LOW);
  224.           digitalWrite(L05, HIGH);
  225.           Serial.println(F("GEAR 4"));
  226.           gear = 4;
  227.           break;
  228.  
  229.         case 5:    //
  230.           digitalWrite(SOL1, HIGH);
  231.           outStatus01 = 0;
  232.           digitalWrite(SOL2, HIGH);
  233.           outStatus02 = 0;
  234.           digitalWrite(SOL3, HIGH);
  235.           outStatus03 = 0;
  236.           digitalWrite(SOL4, HIGH);
  237.           outStatus04 = 0;
  238.           delay(delay45);
  239.           digitalWrite(SOL5, LOW);
  240.           outStatus05 = 1;
  241.           digitalWrite(L01, HIGH);
  242.           digitalWrite(L02, HIGH);
  243.           digitalWrite(L03, HIGH);
  244.           digitalWrite(L04, HIGH);
  245.           digitalWrite(L05, LOW);
  246.           Serial.println(F("GEAR 5"));
  247.           gear = 5;
  248.           break;
  249.       }
  250.     }
  251.     if ( (digitalRead(btn08) == HIGH) && (btnhold == 1) ) {
  252.       btnhold = 0;
  253.       btnStatus08 = 0;
  254.       Serial.println(F("BUTTON LOW"));
  255.     }
  256.  
  257.  
  258.       timer1 = 0;
  259.       msg.bus = 0;
  260.       msg.flags.extended = 0;
  261.       msg.id = 0x1A0;
  262.       msg.len = 8;
  263.       msg.seq = 1;
  264.       msg.buf[0] = gear;
  265.       msg.buf[1] = outStatus01;
  266.       msg.buf[2] = outStatus02;
  267.       msg.buf[3] = outStatus03;
  268.       msg.buf[4] = outStatus04;
  269.       msg.buf[5] = outStatus05;
  270.       msg.buf[6] = outStatus06;
  271.       Can0.write(msg);
  272.     }
  273.  
  274.     void canSniff0(const CAN_message_t &msg) { // global callback
  275.     // you'll need to add all your info and variables to this based on receiving a message.
  276.     // if msg.id == 0x123 {
  277.         msg.buf[0] = shiftup
  278.         msg.buf[1] = shiftdown
  279.       }
  280.  
  281.     // shit like that....
  282.  
  283.  
  284.  
  285.     }
  286.  
  287.  
  288.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top