Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Cablecam code

a guest Apr 10th, 2020 150 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ////////////////////////////////Relais////////////////////////////////
  2. int motor = 7;  
  3. int motorv = A0;
  4. int motorr = A1;
  5. int ledvg = A2;
  6. int ledvr = A3;
  7. int ledhg = A4;
  8. int ledhr = A5;
  9.  
  10. ////////////////////////////////Sensoren////////////////////////////////
  11. int v1=2;                            
  12. int v2=5;
  13. int d2=8;
  14. int d1=9;
  15.  
  16. ////////////////////////////////Schalter////////////////////////////////
  17. int powerSwitch = 10;                
  18. int testSwitch = 11;
  19. int startSwitch = 12;
  20. int killSwitch = 13;
  21. int steuergeraetStart=4;
  22.  
  23. ////////////////////////////////UART Kommandos////////////////////////////////
  24. byte wSpeed = 0x00;                  
  25. byte rSpeed = 0x40;
  26. byte wCurrentLimit = 0x01;
  27. byte rCurrentLimit = 0x41;
  28. byte wRegenCurrentLimit = 0x02;
  29. byte rRegenCurrentLimit = 0x42;
  30. byte wAcceleration = 0x03;
  31. byte rAcceleration = 0x43;
  32. byte wDeceleration = 0x04;
  33. byte rDeceleration = 0x44;
  34. byte wMinVoltOff = 0x05;
  35. byte rMinVoltOff = 0x45;
  36. byte wMinVoltOn = 0x06;
  37. byte rMinVoltOn = 0x46;
  38. byte wMaxVoltOn = 0x07;
  39. byte rMaxVoltOn = 0x47;
  40. byte wMaxVoltOff = 0x08;
  41. byte rMaxVoltOff = 0x48;
  42. byte wLockVar = 0x20;
  43. byte wUnlockVar = 0x21;
  44. byte wSave = 0x22;
  45. byte wAddress = 0x26;
  46. byte wSetConfigBits = 0x30;
  47. byte wResetConfigBits = 0x31;
  48. byte rSuppVolt = 0x4B;
  49. byte rSpeedAdcInput = 0x4C;
  50. byte rLoadCurrent = 0x4D;
  51. byte rStatusRegister = 0x60;
  52.  
  53. ////////////////////////////////Variablen////////////////////////////////
  54. int stop1 = 0;                        
  55. int stop2;
  56. int distanz;
  57. int counter = 0;
  58. int start = 3;
  59. int a = 10;
  60. int b = 50;
  61. int c = 80;
  62. int spot1;
  63. int spot2;
  64. int spot3;
  65. int safety=5;
  66. int ende = 0;
  67. boolean C1 =false;
  68. boolean C2 =false;
  69. boolean C3 =false;
  70. boolean endeC;
  71. boolean power=false;
  72. boolean auge;
  73. boolean playback = false;
  74. int i;
  75.  
  76.  
  77. int address = 0x80;
  78. int answer;
  79. boolean error = true;
  80. int data;
  81. int data1;
  82. int data2;
  83. int crc;
  84. int suppVolt;
  85.  
  86.  
  87. void setup() {
  88.   // put your setup code here, to run once:
  89.  
  90.  
  91.   Serial.begin(38400);
  92.  
  93.   pinMode(v1,INPUT_PULLUP);
  94. pinMode(v2,INPUT_PULLUP);
  95. pinMode(d1,INPUT_PULLUP);
  96. pinMode(d2,INPUT_PULLUP);
  97.   pinMode(powerSwitch, INPUT_PULLUP);
  98.   pinMode(testSwitch, INPUT_PULLUP);
  99.   pinMode(startSwitch, INPUT_PULLUP);
  100.   pinMode(killSwitch, INPUT_PULLUP);
  101.   pinMode(motor, OUTPUT);
  102.   pinMode(motorv, OUTPUT);
  103.   pinMode(motorr, OUTPUT);
  104.   pinMode(ledhr, OUTPUT);
  105.   pinMode(ledvr, OUTPUT);
  106.   pinMode(ledhg, OUTPUT);
  107.   pinMode(ledvg, OUTPUT);
  108.   pinMode(steuergeraetStart, OUTPUT);
  109.  
  110.  
  111. }//end of setup
  112.  
  113.  
  114.  
  115.  
  116.  
  117. void loop() {                               // put your main code here, to run repeatedly:
  118.   lichtAus();
  119.   while (power == false) {                  //arduino hat strom bekommen und wartet auf start Signal
  120.     Serial.println(1);
  121.     if (digitalRead(powerSwitch) == LOW) {
  122.       Serial.println(2);
  123.       power = true;
  124.     }
  125.   }
  126.   digitalWrite(motor, HIGH);
  127.   lichtGelb();                            //Motorsteuergerät und gelbe Positionslichter anschalten
  128.   digitalWrite(steuergeraetStart,HIGH);
  129.   while (Serial.available() == 0) {
  130.     Serial.print(Serial.available());
  131.     delay(1000);
  132.     lichtAus();
  133.     delay(1000);                            //Auf systemstart des Motordrivers warten und Positionslichter gelb blinken
  134.     lichtGelb();
  135.   }
  136. delay(3000);
  137.   address = Serial.read() + 128;
  138.  
  139.   transmitt(wCurrentLimit , 2048);
  140.   transmitt(wMaxVoltOff , 1456);
  141.   transmitt(wMaxVoltOn , 1456);
  142.   transmitt(wMinVoltOff , 1133);
  143.   transmitt(wMinVoltOn , 1133);
  144.   transmitt(wLockVar , 1);
  145.   transmitt(wLockVar , 2);
  146.   transmitt(wLockVar , 4);
  147.   transmitt(wLockVar , 8);
  148.   transmitt(wSetConfigBits , 25);            //11001,brakemode,autobrake,no speed reset, enable configuration bits
  149.   lichtGruen();                              //Systemstart des Steuergerätes und treffen von einstellungen durch grüne positionslichter bestätigen
  150.   delay(1000);
  151.   error = true;
  152.   do {
  153.     if (d1 == LOW && d2 == LOW) {
  154.       error = false;
  155.     }
  156.     lichtRot();
  157.     delay(500);                              //schnell rot blinkende positionslichter bei sensor error
  158.     lichtAus();
  159.     delay(500);
  160.   }
  161.   while (error);
  162.   error = true;
  163. motorVorwaerts();                         //motorbremse aktivieren und positionslichter grün rot
  164.   delay(1000);
  165.   lichtGelb();                              //standby gelbe Positionslichter
  166.  
  167.   //Systemstart abgeschlossen
  168.  
  169. while(error){
  170.  
  171.  
  172.   transmitt(wAcceleration,700);
  173.   transmitt(wSpeed,500);
  174.  
  175.   delay(7000);
  176.   transmitt(wDeceleration,700);
  177.   transmitt(wSpeed,0);
  178.   delay(7000);
  179.   transmitt(wAcceleration,700);
  180.   transmitt(wSpeed,1000);
  181.   delay(7000);
  182.   transmitt(wDeceleration,700);
  183.   transmitt(wSpeed,0);
  184.   delay(7000);
  185.   transmitt(wAcceleration,700);
  186.   transmitt(wSpeed,2000);
  187.   delay(7000);
  188.   transmitt(wDeceleration,700);
  189.   transmitt(wSpeed,0);
  190.   delay(7000);
  191.   transmitt(wAcceleration,700);
  192.   transmitt(wSpeed,3000);
  193.   delay(7000);
  194.   transmitt(wDeceleration,700);
  195.   transmitt(wSpeed,0);
  196.   delay(7000);
  197.   transmitt(wAcceleration,700);
  198.   transmitt(wSpeed,4000);
  199.   delay(7000);
  200.   transmitt(wDeceleration,700);
  201.   transmitt(wSpeed,0);
  202.   delay(7000);
  203. }
  204.  
  205.  
  206.   while (power == true) {                     //dauerbetrieb startet
  207.    
  208.  
  209.     if (digitalRead(startSwitch) == HIGH) {
  210.       playback = true;
  211.       C1 = false;
  212.       C2 = false;
  213.       C3 = false;
  214.       ende = false;
  215.       while (playback == true) {
  216.  
  217.         if(d1==HIGH||d2==HIGH){
  218.           killBreak;
  219.         }
  220.         if(digitalRead(v1) == HIGH) {
  221.           auge = true;
  222.           if (motorv == HIGH) {
  223.             counter++;            //Distanz messen
  224.           }
  225.           if (motorr == HIGH) {
  226.             counter--;            //Distanz messen
  227.           }
  228.           while (auge == true) {
  229.             if (digitalRead(v1) == LOW) {
  230.               auge = false;
  231.             }//end of if
  232.           }//end of while
  233.           while (auge == false) {
  234.             if (digitalRead(v1) == HIGH) {
  235.               auge = true;
  236.             }//end of if
  237.           }//end of while
  238.         }//end of if
  239.  
  240.         if (counter == start) {
  241.           transmitt(wAcceleration, 1000);
  242.           transmitt(wSpeed, 1000);
  243.         }
  244.         if (counter == spot1 && C1 == false) {
  245.           transmitt(wDeceleration, 1000);
  246.           transmitt(wSpeed, 0);
  247.           C1 = true;
  248.         }
  249.         if (counter == spot2 && C2== false) {
  250.           transmitt(wAcceleration, 0x01);
  251.           transmitt(wSpeed, 3000);
  252.           C2 = true;
  253.         }
  254.         if (counter == spot3 && C3 == false) {
  255.           transmitt(wDeceleration, 300);
  256.           transmitt(wSpeed, 400);
  257.           C3 = true;
  258.         }
  259.         if (counter == ende) {
  260.           transmitt(wDeceleration, 100);
  261.           transmitt(wSpeed, 0)  ;
  262.           endeC = true;
  263.         }
  264.         if (counter > (ende - 20) && C3 == false) { //es muss das Komando zum anhalten in spot3 gegeben werden/Check variable des letzten kommandos vor ende muss geprüft werden
  265.           transmitt(wDeceleration, 300);
  266.           transmitt(wSpeed, 400);
  267.         }
  268.  
  269.         if (digitalRead(killSwitch) == HIGH) {
  270.           killBreak();
  271.           playback = false;
  272.         }
  273.       }
  274.  
  275.  
  276.     }
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.     if (digitalRead(powerSwitch) == HIGH) {
  287.  
  288.       lichtAus();
  289.       delay(500);
  290.       lichtGelb();
  291.       delay(1000);
  292.       power = false;                //kick aus dauerbetrieb schleife
  293.     }
  294.   }                                 //end of while  ende des dauerbetriebs
  295.   digitalWrite(motor, LOW);         //abschalt Sequenz
  296.   lichtGruen();
  297.   delay(1000);
  298.   lichtGelb();
  299.   delay(1000);
  300.   for (i = 0; i < 4; i++) {
  301.     lichtRot();
  302.     delay(1000);
  303.     lichtAus();
  304.     delay(1000);
  305.   }
  306.   lichtRot();
  307.   delay(3000);
  308.   lichtAus();
  309.   while (power == false) {
  310.     if (digitalRead(powerSwitch) == HIGH) {
  311.       power = true;                                            //programm neu starten, zu beginn des loop springen, Systemstart
  312.     }
  313.   }
  314.  
  315.  
  316.  
  317.  
  318.  
  319. }//end of loop
  320.  
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.  
  328.  
  329. void transmitt(int command , int data) {
  330.  
  331.   do {
  332.     Serial.write(address);
  333.     Serial.write(command);
  334.     data1 = (data - (data % 128)) / 128;              //Datenwert wird in zwei 7Bit Bytes aufgeteilt
  335.     data2 = data % 128;
  336.     Serial.write(data1);
  337.     Serial.write(data2);
  338.     crc = (command + data1 + data2) & 127;            //CRC Byte Berechnung
  339.     Serial.write(crc);
  340.     while (Serial.available() == 0) {}                //auf Bestätigung/ERROR warten
  341.     answer = Serial.read();
  342.     if (answer == address) {
  343.       error = false;
  344.     }//end of if
  345.     if (answer == (0x80 | address)) {
  346.       error = true;                                   //wenn Übertragungserror Befehl wird wiederholt
  347.     }//end of if
  348.   }//end of do
  349.   while (error);
  350.  
  351. }//end of transmitt
  352.  
  353.  
  354.  
  355. void receive(int command) {
  356.  
  357.   do {
  358.     Serial.write(address);
  359.     Serial.write(command);
  360.     while (Serial.available() == 0) {}                //auf erstes Datenbyte warten
  361.     data1 = Serial.read();
  362.     while (Serial.available() == 0) {}                //auf zweites Datenbyte warten
  363.     data2 = Serial.read();
  364.     while (Serial.available() == 0) {}                //auf CRC Byte warten
  365.     crc = Serial.read();
  366.     data = data1 * 128 + data2;
  367.     error = false;
  368.     if (crc != (command + data1 + data2) & 127) {
  369.       error = true;                                   //wenn Übertragungserror Befehl wird wiederholt
  370.     }//end of if
  371.   }//end of do
  372.   while (error);
  373.  
  374. }//end of transmitt
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381. void testlauf() {
  382.   distanz = 0;
  383.   if (digitalRead(d2) == LOW) {
  384.     motorVorwaerts();
  385.     transmitt(wSpeed, 10);
  386.     while (digitalRead(d2) == LOW) {} //in eine Richtung bis zum ende fahren
  387.     transmitt(wSpeed , 0);
  388.     delay(1000);
  389.     motorRueckwaerts();
  390.     transmitt(wSpeed , 10);                     //in die Gegenrichtung bis zum Ende fahren
  391.     while (digitalRead(d1) == LOW) {
  392.       if (digitalRead(v1) == HIGH) {
  393.         auge = true;
  394.         distanz++;                  //Distanz messen
  395.         while (auge == true) {
  396.           if (digitalRead(v1) == LOW) {
  397.             auge = false;
  398.           }//end of if
  399.         }//end of while
  400.         while (auge == false) {
  401.           if (digitalRead(v1) == HIGH) {
  402.             auge = true;
  403.           }//end of if
  404.         }//end of while
  405.       }//end of if
  406.     }//end of while
  407.     transmitt(wSpeed , 0);
  408.     stop2 = distanz;
  409.     start = safety;
  410.     ende = distanz - safety;
  411.     delay(1000);
  412.  
  413.   }//end of if
  414.  
  415. }//end of testlauf
  416.  
  417.  
  418. void setStrecke() {
  419.   distanz = 45;
  420.   stop1 = 23;
  421.   stop2 = 67;
  422. }//end of setStrecke
  423.  
  424.  
  425.  
  426. void killBreak() {
  427.   motorVorwaerts();
  428.   transmitt(wDeceleration, 0x0001);
  429.   transmitt(wSpeed, 0);
  430. }
  431.  
  432. void motorVorwaerts() {
  433.   digitalWrite(motorr, LOW);
  434.   lichtGruenRot();
  435.   digitalWrite(motorv, HIGH);
  436. }
  437.  
  438. void motorRueckwaerts() {
  439.   digitalWrite(motorv, LOW);
  440.   lichtRotGruen();
  441.   digitalWrite(motorr, HIGH);
  442. }
  443.  
  444. void lichtAus() {
  445.   digitalWrite(ledvr, HIGH);
  446.   digitalWrite(ledhg, HIGH);
  447.   digitalWrite(ledvg, HIGH);
  448.   digitalWrite(ledhr, HIGH);
  449.  
  450. }
  451. void lichtGelb() {
  452.   digitalWrite(ledvr, LOW);
  453.   digitalWrite(ledhg, LOW);
  454.   digitalWrite(ledvg, LOW);
  455.   digitalWrite(ledhr, LOW);
  456. }
  457. void lichtGruen() {
  458.   digitalWrite(ledvr, HIGH);
  459.   digitalWrite(ledhg, LOW);
  460.   digitalWrite(ledvg, LOW);
  461.   digitalWrite(ledhr, HIGH);
  462. }
  463. void lichtRot() {
  464.   digitalWrite(ledvr, LOW);
  465.   digitalWrite(ledhg, HIGH);
  466.   digitalWrite(ledvg, HIGH);
  467.   digitalWrite(ledhr, LOW);
  468. }
  469. void lichtRotGruen() {
  470.   digitalWrite(ledvr, LOW);
  471.   digitalWrite(ledhg, LOW);
  472.   digitalWrite(ledvg, HIGH);
  473.   digitalWrite(ledhr, HIGH);
  474. }
  475. void lichtGruenRot() {
  476.   digitalWrite(ledvr, HIGH);
  477.   digitalWrite(ledhg, HIGH);
  478.   digitalWrite(ledvg, LOW);
  479.   digitalWrite(ledhr, LOW);
  480. }
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
Top