Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- SCL (SPI Clock) Pin 13
- SI (MOSI) Pin 11
- CS (Chip Select) Pin 10
- A0 PIN 9
- MISO (Pin 12) is not used, but can not be reused as generic I/O
- Note:
- 1) Set correct display hardware in Dogm/utility/dogm128.h
- 2) Set top/bottom view (DOG_REVERSE) in Dogm/utility/dogm128.h
- See also: http://code.google.com/p/dogm128/wiki/install
- */
- #include <Dogm.h>
- #include <Wire.h>
- extern const dog_pgm_uint8_t emc2_30[]; //EMC2 font
- int a0Pin = 9; // address line a0 for the dogm module
- int sensorPin = 0; // analog input
- int runState = 1; // programm status 0 = Estop
- int rotaryPCBadr = B00100000;//PCF8574 ID
- int displaySwitchadr = B00100111;
- int dirArrowAdr = B00100011;
- int axisSelected = 4; // var that storces the Selscted Axis
- float incrementSelected = 0; // var that storces the Selscted Increment
- byte buttonAction = 1;
- int buttonPressed = 0; // var stores button pressed
- byte mfgAction = 0;
- byte mfgDir = 3;
- float xValue = 1234.567;
- float yValue = 123.456;
- float zValue = 12.345;
- float feed = 100;
- int rpm = 5000;
- int mcode = 2;
- Dogm dogm(a0Pin);
- void setup() {
- Serial.begin(9600);
- Wire.begin(); // join i2c bus (address optional for master)
- attachInterrupt(0, i2cAction, FALLING);
- Serial.println("Welcome");
- }
- int zahl = 0;
- int i = 90;
- void loop() {
- // check the button States
- if (buttonAction == 1)
- {
- byte _readin;
- _readin = expanderRead(displaySwitchadr);
- // check eStop pressed FIRST
- if (_readin == B11111110 )eStop();
- if (bitRead(_readin,1) == 0) buttonPressed =1;// opt button A
- if (bitRead(_readin,2) == 0) buttonPressed =2;// opt button B
- if (bitRead(_readin,3) == 0) buttonPressed =3;// button RED
- if (bitRead(_readin,4) == 0) buttonPressed =4;// button Blue
- if (bitRead(_readin,5) == 0) buttonPressed =5;// opt button A
- if (bitRead(_readin,6) == 0) buttonPressed =6;// button Green
- if (bitRead(_readin,7) == 0) buttonPressed =7;// button Yellow
- //delay(5);
- _readin = expanderRead(rotaryPCBadr);
- if (bitRead(_readin,4) == 0) axisSelected = 0;
- if (bitRead(_readin,5) == 0) axisSelected = 1;
- if (bitRead(_readin,6) == 0) axisSelected = 2;
- if (bitRead(_readin,0) == 0) incrementSelected = 0.01;
- if (bitRead(_readin,1) == 0) incrementSelected = 0.1;
- if (bitRead(_readin,2) == 0) incrementSelected = 1;
- if (bitRead(_readin,3) == 0) incrementSelected = 10;
- //Serial.println(_readin,BIN);
- buttonAction = 0;
- }
- //runState=2;
- // new Runstate ?
- if ((runState == 1) && (buttonPressed == 7))runState=2;// from welcome to Main_Meue
- if ((runState == 2) && (buttonPressed == 2))runState=3;// from Main_menue to Manuell
- if ((runState == 3) && (buttonPressed == 7))runState=2;// from Manuell to Main_Menue
- // show Display
- if (runState == 1) welcome();
- if (runState == 0 )eStop();
- if (runState == 2 )main_menue();
- if (runState == 3 )manuell_menue();
- }
- void welcome(){
- DOG_PGM_P p;
- dogm.start();
- if (i>110) i=90;
- do{
- p = font_6x13;
- dogm.setFont(p);
- dogm.setXY(0,2);
- dogm.print("GERMANY");
- dogm.setXY(0,15);
- dogm.print("Sammel Lothar");
- dogm.setXY(75,53);
- dogm.print("2.5/AXIS");
- p = font_5x8;
- dogm.setFont(p);
- dogm.setXY(3,30);
- dogm.print("Mill Pendant V1");
- p = emc2_30;
- dogm.setFont(p);
- dogm.setXY(0,40);
- dogm.print("EMC");
- dogm.clrBox(79,14,126,50);
- dogm.setBox(84,15,88,22);
- dogm.setBox(116,15,120,22);
- dogm.setBox(81,22,123,24);
- dogm.setHLine(82,124,33);
- dogm.setHLine(82,124,36);
- dogm.setHLine(82,124,37);
- dogm.setHLine(82,124,40);
- //
- dogm.setVLine(80,25,43);
- dogm.setVLine(82,25,42);
- dogm.setVLine(122,25,42);
- dogm.setVLine(124,25,43);
- //
- dogm.setVLine(81,25,40);
- dogm.setVLine(123,25,40);
- // Bohrer
- dogm.setBox(i,30,i+4,47);
- dogm.setXY(i+2,49);
- dogm.setHLine(i+1,i+3,48);
- dogm.setHLine(i+1,i+3,29);
- dogm.setVLine(i+2,26,29);
- dogm.clrVLine(i+2,32,41);
- // menue
- dogm.setHLine(96,128,15);
- dogm.setVLine(96,0,15);
- p = font_6x13;
- dogm.setFont(p);
- dogm.setXY(99,3);
- dogm.print("START");
- }while( dogm.next() );
- dog_Delay(200);
- i++;
- }
- void eStop(){
- DOG_PGM_P p;
- dogm.start();
- int ystart = 24 ;
- int leng = 22;
- int yend;
- do{
- // stop sign
- for (int x=34;x<95;x++){
- if (x<52){
- ystart--;
- leng = leng + 2;
- yend = ystart + leng;
- }
- if (x>76){
- ystart++;
- leng = leng - 2;
- yend = ystart + leng;
- }
- dogm.setVLine(x,ystart,yend);
- }
- dogm.clrBox(44,27,84,43);
- p = font_6x13;
- dogm.setFont(p);
- dogm.setXY(47,30);
- dogm.print("E-STOP");
- dogm.setXY(0,16);
- dogm.print("PRESS");
- dogm.setXY(6,5);
- dogm.print("RED");
- }while( dogm.next() );
- dog_Delay(500);
- delay(1000);
- while (expanderRead(displaySwitchadr) != B11110111) // red Button
- {
- delay(200);
- }
- buttonAction = 0;
- runState = 0;
- delay(200);
- }
- void main_menue(){
- DOG_PGM_P p;
- dogm.start();
- do{
- // menue
- dogm.setHLine(0,128,15);
- dogm.setVLine(0,0,15);
- dogm.setVLine(32,0,15);
- dogm.setVLine(64,0,15);
- dogm.setVLine(96,0,15);
- dogm.setVLine(128,0,15);
- p = font_6x13;
- dogm.setFont(p);
- dogm.setXY(14,2);
- dogm.print("A");
- dogm.setXY(46,2);
- dogm.print("B");
- dogm.setXY(78,2);
- dogm.print("C");
- //dogm.setXY(98,3);
- //dogm.print("D");
- dogm.setXY(10,44);
- dogm.print("A -> Anfahren");
- dogm.setXY(10,30);
- dogm.print("B -> Manuell");
- dogm.setXY(10,16);
- dogm.print("C -> Programm");
- // info
- p = font_5x8;
- dogm.setFont(p);
- dogm.setXY(50,57);
- dogm.print("Main Menue");
- }while( dogm.next() );
- dog_Delay(5);
- delay(5);
- }
- void manuell_menue(){
- DOG_PGM_P p;
- dogm.start();
- do{
- // menue
- dogm.setHLine(0,128,15);
- dogm.setVLine(0,0,15);
- dogm.setVLine(32,0,15);
- dogm.setVLine(64,0,15);
- dogm.setVLine(96,0,15);
- dogm.setVLine(128,0,15);
- p = font_6x13;
- dogm.setFont(p);
- dogm.setXY(14,2);
- dogm.print("F");
- dogm.setXY(46,2);
- dogm.print("S");
- dogm.setXY(78,2);
- dogm.print("M");
- dogm.setXY(98,3);
- dogm.print("MENUE");
- // Axis
- int y;
- switch (axisSelected) {
- case 0: // X selected
- y = 42;
- break;
- case 1: // Y selected
- y = 29;
- break;
- case 2: // Z selected
- y =16 ;
- break;
- case 4: // Z selected
- y = 64 ;
- break;
- }
- //dogm.setBox(0,y,15,y+14);
- //dogm.clrBox(3,y+2,12,y+12);
- dogm.setXY(5,44);
- dogm.print("X");
- dogm.setXY(5,31);
- dogm.print("Y");
- dogm.setXY(5,18);
- dogm.print("Z");
- dogm.xorBox(0,y,15,y+14);
- // axis Values
- dogm.setXY(60-lengthText(xValue),44);
- dogm.print(xValue,3);
- dogm.setXY(60-lengthText(yValue),31);
- dogm.print(yValue,3);
- dogm.setXY(60-lengthText(zValue),18);
- dogm.print(zValue,3);
- // info
- p = font_5x8;
- dogm.setFont(p);
- dogm.setXY(5,57);
- dogm.print("Manuell Offline ");
- dogm.setXY(75,18);
- dogm.print("Incrm:");
- dogm.setXY(80,27);
- dogm.print("M:");
- dogm.setXY(80,37);
- dogm.print("S:");
- dogm.setXY(80,47);
- dogm.print("F:");
- dogm.setXY(105,18);
- dogm.print(incrementSelected);
- dogm.setXY(92,27);
- dogm.print(mcode);
- dogm.setXY(92,37);
- dogm.print(rpm);
- dogm.setXY(92,47);
- dogm.print(feed);
- }while( dogm.next() );
- dog_Delay(10);
- delay(10);
- }
- byte expanderRead(int adr) {
- byte _data;
- Wire.requestFrom(adr, 1);
- if(Wire.available()) {
- _data = Wire.receive();
- }
- return _data;
- }
- int lengthText(float value)
- {
- int _length;
- if (value >= 0) _length = 18;
- if (value >= 10) _length = 24;
- if (value >= 100) _length = 30;
- if (value >= 1000)_length = 36;
- if (value < 0) _length = 24;
- if (value < -10) _length = 30;
- if (value < -100) _length = 36;
- if (value < -1000)_length = 42;
- return _length;
- }
- void i2cAction(){
- buttonAction = 1 ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement