Advertisement
Guest User

arduino pendand v1 A022

a guest
Jan 5th, 2013
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*  
  2.  
  3.   SCL (SPI Clock)   Pin 13
  4.   SI (MOSI)         Pin 11
  5.   CS (Chip Select)  Pin 10
  6.   A0                PIN 9
  7.   MISO (Pin 12) is not used, but can not be reused as generic I/O
  8.  
  9.   Note:
  10.     1) Set correct display hardware in Dogm/utility/dogm128.h
  11.     2) Set top/bottom view (DOG_REVERSE) in Dogm/utility/dogm128.h
  12.     See also: http://code.google.com/p/dogm128/wiki/install
  13.  
  14. */
  15.  
  16. #include <Dogm.h>
  17. #include <Wire.h>
  18.  
  19. extern const dog_pgm_uint8_t emc2_30[]; //EMC2 font
  20. int a0Pin = 9;      // address line a0 for the dogm module
  21. int sensorPin = 0;  // analog input
  22. int runState = 1; // programm status 0 = Estop
  23. int rotaryPCBadr = B00100000;//PCF8574 ID
  24. int displaySwitchadr = B00100111;
  25. int dirArrowAdr = B00100011;
  26. int axisSelected = 4; // var that storces the Selscted Axis
  27. float incrementSelected = 0; // var that storces the Selscted Increment
  28.  
  29. byte buttonAction = 1;
  30. int buttonPressed = 0; // var stores button pressed
  31. byte mfgAction = 0;
  32. byte mfgDir = 3;
  33. float xValue = 1234.567;
  34. float yValue = 123.456;
  35. float zValue = 12.345;
  36. float feed = 100;
  37. int rpm = 5000;
  38. int mcode = 2;
  39. Dogm dogm(a0Pin);
  40.  
  41. void setup() {
  42.   Serial.begin(9600);
  43.   Wire.begin(); // join i2c bus (address optional for master)
  44.   attachInterrupt(0, i2cAction, FALLING);
  45.   Serial.println("Welcome");
  46. }
  47.  
  48. int zahl = 0;
  49. int i = 90;
  50.  
  51. void loop() {
  52.   // check the button States
  53.   if (buttonAction == 1)
  54.   {  
  55.     byte _readin;
  56.     _readin = expanderRead(displaySwitchadr);
  57.     // check eStop pressed FIRST
  58.     if (_readin == B11111110 )eStop();
  59.     if (bitRead(_readin,1) == 0) buttonPressed =1;// opt button A
  60.     if (bitRead(_readin,2) == 0) buttonPressed =2;// opt button B
  61.     if (bitRead(_readin,3) == 0) buttonPressed =3;// button RED
  62.     if (bitRead(_readin,4) == 0) buttonPressed =4;// button Blue
  63.     if (bitRead(_readin,5) == 0) buttonPressed =5;// opt button A
  64.     if (bitRead(_readin,6) == 0) buttonPressed =6;// button  Green
  65.     if (bitRead(_readin,7) == 0) buttonPressed =7;// button Yellow
  66.     //delay(5);
  67.     _readin = expanderRead(rotaryPCBadr);
  68.     if (bitRead(_readin,4) == 0) axisSelected = 0;
  69.     if (bitRead(_readin,5) == 0) axisSelected = 1;
  70.     if (bitRead(_readin,6) == 0) axisSelected = 2;
  71.     if (bitRead(_readin,0) == 0) incrementSelected = 0.01;
  72.     if (bitRead(_readin,1) == 0) incrementSelected = 0.1;
  73.     if (bitRead(_readin,2) == 0) incrementSelected = 1;
  74.     if (bitRead(_readin,3) == 0) incrementSelected = 10;
  75.  
  76.     //Serial.println(_readin,BIN);
  77.  
  78.     buttonAction = 0;
  79.  
  80.   }
  81.  
  82.   //runState=2;
  83.   // new Runstate ?
  84.   if ((runState == 1) && (buttonPressed == 7))runState=2;// from welcome to Main_Meue  
  85.   if ((runState == 2) && (buttonPressed == 2))runState=3;// from Main_menue to Manuell  
  86.   if ((runState == 3) && (buttonPressed == 7))runState=2;// from Manuell to Main_Menue
  87.  
  88.   // show Display  
  89.  
  90.   if (runState == 1) welcome();
  91.   if (runState == 0 )eStop();
  92.   if (runState == 2 )main_menue();
  93.   if (runState == 3 )manuell_menue();
  94.  
  95. }
  96.  
  97. void welcome(){
  98.   DOG_PGM_P p;
  99.   dogm.start();
  100.   if (i>110) i=90;
  101.    
  102.   do{
  103.   p = font_6x13;
  104.   dogm.setFont(p);
  105.   dogm.setXY(0,2);
  106.   dogm.print("GERMANY");
  107.   dogm.setXY(0,15);
  108.   dogm.print("Sammel Lothar");
  109.   dogm.setXY(75,53);
  110.   dogm.print("2.5/AXIS");
  111.   p = font_5x8;
  112.   dogm.setFont(p);
  113.   dogm.setXY(3,30);
  114.   dogm.print("Mill Pendant V1");
  115.   p = emc2_30;
  116.   dogm.setFont(p);
  117.   dogm.setXY(0,40);
  118.   dogm.print("EMC");
  119.   dogm.clrBox(79,14,126,50);
  120.   dogm.setBox(84,15,88,22);
  121.   dogm.setBox(116,15,120,22);
  122.   dogm.setBox(81,22,123,24);
  123.   dogm.setHLine(82,124,33);
  124.   dogm.setHLine(82,124,36);
  125.   dogm.setHLine(82,124,37);
  126.   dogm.setHLine(82,124,40);
  127.   //
  128.   dogm.setVLine(80,25,43);
  129.   dogm.setVLine(82,25,42);
  130.   dogm.setVLine(122,25,42);
  131.   dogm.setVLine(124,25,43);
  132.   //
  133.   dogm.setVLine(81,25,40);
  134.   dogm.setVLine(123,25,40);
  135.   // Bohrer
  136.   dogm.setBox(i,30,i+4,47);
  137.   dogm.setXY(i+2,49);
  138.   dogm.setHLine(i+1,i+3,48);
  139.   dogm.setHLine(i+1,i+3,29);
  140.   dogm.setVLine(i+2,26,29);
  141.   dogm.clrVLine(i+2,32,41);
  142.   // menue
  143.   dogm.setHLine(96,128,15);
  144.   dogm.setVLine(96,0,15);
  145.   p = font_6x13;
  146.   dogm.setFont(p);
  147.   dogm.setXY(99,3);
  148.   dogm.print("START");
  149.  
  150.   }while( dogm.next() );
  151.    dog_Delay(200);
  152.   i++;
  153. }
  154. void eStop(){
  155.   DOG_PGM_P p;
  156.   dogm.start();
  157.   int ystart = 24 ;
  158.   int leng = 22;
  159.   int yend;
  160.   do{
  161.     // stop sign
  162.     for (int x=34;x<95;x++){
  163.       if (x<52){
  164.       ystart--;
  165.       leng = leng + 2;
  166.       yend = ystart + leng;
  167.       }
  168.       if (x>76){
  169.       ystart++;
  170.       leng = leng - 2;
  171.       yend = ystart + leng;
  172.       }
  173.       dogm.setVLine(x,ystart,yend);
  174.     }
  175.     dogm.clrBox(44,27,84,43);
  176.     p = font_6x13;
  177.     dogm.setFont(p);
  178.     dogm.setXY(47,30);
  179.     dogm.print("E-STOP");
  180.     dogm.setXY(0,16);
  181.     dogm.print("PRESS");
  182.     dogm.setXY(6,5);
  183.     dogm.print("RED");
  184.        
  185.     }while( dogm.next() );
  186.   dog_Delay(500);
  187.   delay(1000);
  188.   while (expanderRead(displaySwitchadr) != B11110111) // red Button
  189.   {
  190.     delay(200);
  191.   }
  192.   buttonAction = 0;
  193.   runState = 0;
  194.   delay(200);
  195. }
  196.  
  197. void main_menue(){
  198.   DOG_PGM_P p;
  199.   dogm.start();
  200.   do{
  201.   // menue
  202.   dogm.setHLine(0,128,15);
  203.   dogm.setVLine(0,0,15);
  204.   dogm.setVLine(32,0,15);
  205.   dogm.setVLine(64,0,15);
  206.   dogm.setVLine(96,0,15);
  207.   dogm.setVLine(128,0,15);
  208.   p = font_6x13;
  209.   dogm.setFont(p);
  210.   dogm.setXY(14,2);
  211.   dogm.print("A");
  212.   dogm.setXY(46,2);
  213.   dogm.print("B");
  214.   dogm.setXY(78,2);
  215.   dogm.print("C");
  216.   //dogm.setXY(98,3);
  217.   //dogm.print("D");
  218.   dogm.setXY(10,44);
  219.   dogm.print("A -> Anfahren");
  220.   dogm.setXY(10,30);
  221.   dogm.print("B -> Manuell");
  222.   dogm.setXY(10,16);
  223.   dogm.print("C -> Programm");
  224.   // info
  225.   p = font_5x8;
  226.   dogm.setFont(p);
  227.   dogm.setXY(50,57);
  228.   dogm.print("Main Menue");
  229.   }while( dogm.next() );
  230.   dog_Delay(5);
  231.   delay(5);
  232.  }
  233.  
  234.  
  235. void manuell_menue(){
  236.   DOG_PGM_P p;
  237.   dogm.start();
  238.   do{
  239.   // menue
  240.   dogm.setHLine(0,128,15);
  241.   dogm.setVLine(0,0,15);
  242.   dogm.setVLine(32,0,15);
  243.   dogm.setVLine(64,0,15);
  244.   dogm.setVLine(96,0,15);
  245.   dogm.setVLine(128,0,15);
  246.   p = font_6x13;
  247.   dogm.setFont(p);
  248.   dogm.setXY(14,2);
  249.   dogm.print("F");
  250.   dogm.setXY(46,2);
  251.   dogm.print("S");
  252.   dogm.setXY(78,2);
  253.   dogm.print("M");
  254.   dogm.setXY(98,3);
  255.   dogm.print("MENUE");
  256.   //  Axis
  257.   int y;
  258.   switch (axisSelected) {
  259.     case 0: // X selected
  260.       y = 42;
  261.       break;
  262.     case 1: // Y selected
  263.       y = 29;
  264.       break;
  265.     case 2: // Z selected
  266.       y =16 ;
  267.       break;
  268.     case 4: // Z selected
  269.       y = 64 ;
  270.       break;
  271.  
  272.    }
  273.   //dogm.setBox(0,y,15,y+14);
  274.   //dogm.clrBox(3,y+2,12,y+12);
  275.   dogm.setXY(5,44);
  276.   dogm.print("X");
  277.   dogm.setXY(5,31);
  278.   dogm.print("Y");
  279.   dogm.setXY(5,18);
  280.   dogm.print("Z");
  281.   dogm.xorBox(0,y,15,y+14);
  282.   // axis Values
  283.   dogm.setXY(60-lengthText(xValue),44);
  284.   dogm.print(xValue,3);
  285.   dogm.setXY(60-lengthText(yValue),31);
  286.   dogm.print(yValue,3);
  287.   dogm.setXY(60-lengthText(zValue),18);
  288.   dogm.print(zValue,3);
  289.   // info
  290.   p = font_5x8;
  291.   dogm.setFont(p);
  292.   dogm.setXY(5,57);
  293.   dogm.print("Manuell    Offline ");
  294.   dogm.setXY(75,18);
  295.   dogm.print("Incrm:");
  296.   dogm.setXY(80,27);
  297.   dogm.print("M:");
  298.   dogm.setXY(80,37);
  299.   dogm.print("S:");
  300.   dogm.setXY(80,47);
  301.   dogm.print("F:");
  302.   dogm.setXY(105,18);
  303.   dogm.print(incrementSelected);
  304.   dogm.setXY(92,27);
  305.   dogm.print(mcode);
  306.   dogm.setXY(92,37);
  307.   dogm.print(rpm);
  308.   dogm.setXY(92,47);
  309.   dogm.print(feed);
  310.   }while( dogm.next() );
  311.   dog_Delay(10);
  312.   delay(10);
  313.  
  314. }
  315.  
  316. byte expanderRead(int adr) {
  317.   byte _data;
  318.   Wire.requestFrom(adr, 1);
  319.   if(Wire.available()) {
  320.     _data = Wire.receive();
  321.   }
  322.   return _data;
  323. }
  324.  
  325. int lengthText(float value)
  326. {
  327.  int _length;
  328.  if (value >= 0)   _length = 18;
  329.  if (value >= 10)  _length = 24;
  330.  if (value >= 100) _length = 30;
  331.  if (value >= 1000)_length = 36;
  332.  if (value < 0)    _length = 24;
  333.  if (value < -10)  _length = 30;
  334.  if (value < -100) _length = 36;
  335.  if (value < -1000)_length = 42;
  336.  return  _length;
  337.  
  338. }
  339.  
  340. void i2cAction(){
  341.   buttonAction = 1 ;
  342.  
  343. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement