78 u8g2 =
new U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI(U8G2_R0, 11, 9, U8X8_PIN_NONE, 2, 10);
81 void egoShield::setup(uint16_t acc, uint16_t vel, uint8_t uStep, uint16_t fTol, uint16_t fHys,
float P,
float I,
float D,
float res)
88 WDTCSR = (1 << WDCE) | (1 << WDE);
89 WDTCSR |= (1 << WDIE) | (1 << WDE);
115 u8g2->setFontMode(1);
116 u8g2->setDrawColor(1);
117 u8g2->setFontDirection(0);
118 u8g2->setFont(u8g2_font_6x10_tf);
120 u8g2->drawStr(2,10,
"Magnet not present !");
121 }
while (
u8g2->nextPage() );
123 while(
stepper.encoder.detectMagnet() == 2 ||
stepper.encoder.detectMagnet() == 1);
131 while(
stepper.getMotorState());
135 pinMode(
FWBT ,INPUT);
136 pinMode(
PLBT ,INPUT);
137 pinMode(
RECBT ,INPUT);
138 pinMode(
BWBT ,INPUT);
139 pinMode(
OPTO,OUTPUT);
140 digitalWrite(
OPTO ,HIGH);
141 digitalWrite(
FWBT ,HIGH);
142 digitalWrite(
PLBT ,HIGH);
143 digitalWrite(
RECBT ,HIGH);
144 digitalWrite(
BWBT ,HIGH);
178 static bool continousForward = 0;
179 static bool continousBackwards = 0;
188 continousForward = 0;
191 else if(continousBackwards)
196 continousBackwards = 0;
205 continousForward = 0;
206 continousBackwards = 0;
231 if(!continousForward)
234 continousForward = 1;
248 if(!continousBackwards)
251 continousBackwards = 1;
264 continousForward = 0;
265 continousBackwards = 0;
272 static uint8_t started = 0;
369 if(speedDirection && this->velocity <= 9900 && this->
acceleration <= 19900)
385 static bool continousForward = 0;
386 static bool continousBackwards = 0;
395 continousForward = 0;
398 else if(continousBackwards)
403 continousBackwards = 0;
410 if(!continousForward)
413 continousForward = 1;
427 if(!continousBackwards)
430 continousBackwards = 1;
468 continousForward = 0;
469 continousBackwards = 0;
509 u8g2->drawXBM(19, 20, logo_width, logo_height, logo_bits);
510 }
while (
u8g2->nextPage() );
521 sBuf.toCharArray(buf, 20);
525 u8g2->drawBox(1, 1, 128, 12);
526 u8g2->drawBox(1, 48, 128, 68);
527 u8g2->setFontMode(0);
528 u8g2->setDrawColor(0);
529 u8g2->setFontDirection(0);
530 u8g2->setFont(u8g2_font_6x10_tf);
533 u8g2->drawXBM(5, 51, en_width, en_height, bw_bits);
534 u8g2->drawXBM(112, 51, en_width, en_height, fw_bits);
535 u8g2->drawXBM(32, 50, play_width, play_height, play_bits);
536 u8g2->drawXBM(43, 51, tt_width, tt_height, stop_bits);
537 u8g2->drawXBM(71, 51, tt_width, tt_height, rec_bits);
538 u8g2->drawXBM(85, 51, tt_width, tt_height, pse_bits);
541 u8g2->drawStr(2,10,
"Idle");
544 u8g2->drawStr(45,10,
"PID ON");
548 u8g2->drawStr(45,10,
"PID OFF");
550 u8g2->setFontMode(1);
551 u8g2->setDrawColor(1);
552 u8g2->drawStr(2,35,buf);
553 }
while (
u8g2->nextPage() );
564 u8g2->drawBox(1, 1, 128, 12);
565 u8g2->drawBox(1, 48, 128, 68);
566 u8g2->setFontMode(0);
567 u8g2->setDrawColor(0);
568 u8g2->setFontDirection(0);
569 u8g2->setFont(u8g2_font_6x10_tf);
571 u8g2->drawXBM(5, 51, en_width, en_height, bw_bits);
572 u8g2->drawXBM(112, 51, en_width, en_height, fw_bits);
573 u8g2->drawXBM(38, 51, tt_width, tt_height, stop_bits);
574 u8g2->drawXBM(76, 51, tt_width, tt_height, rec_bits);
577 u8g2->drawStr(2,10,
"Record");
580 u8g2->drawStr(45,10,
"PID ON");
584 u8g2->drawStr(45,10,
"PID OFF");
586 u8g2->setFontMode(1);
587 u8g2->setDrawColor(1);
593 sBuf.toCharArray(buf, 22);
594 u8g2->drawStr(2,35,buf);
601 sBuf.toCharArray(buf, 22);
602 u8g2->drawStr(2,35,buf);
604 }
while (
u8g2->nextPage() );
614 u8g2->drawBox(1, 1, 128, 12);
615 u8g2->drawBox(1, 48, 128, 68);
616 u8g2->setFontMode(0);
617 u8g2->setDrawColor(0);
618 u8g2->setFontDirection(0);
619 u8g2->setFont(u8g2_font_6x10_tf);
623 u8g2->drawXBM(110, 2, loop_width, loop_height, loop_bits);
627 u8g2->drawXBM(5, 51, en_width, en_height, bw_bits);
628 u8g2->drawXBM(112, 51, en_width, en_height, fw_bits);
629 u8g2->drawXBM(32, 50, play_width, play_height, play_bits);
630 u8g2->drawXBM(43, 51, tt_width, tt_height, stop_bits);
631 u8g2->drawXBM(77, 51, tt_width, tt_height, pse_bits);
634 u8g2->drawStr(2,10,
"Play");
637 u8g2->drawStr(45,10,
"PID ON");
641 u8g2->drawStr(45,10,
"PID OFF");
643 u8g2->setFontMode(1);
644 u8g2->setDrawColor(1);
651 u8g2->drawStr(2,25,
"Moving to pos");
652 String(index).toCharArray(buf, 5);
653 u8g2->drawStr(90,25,buf);
655 u8g2->drawStr(2,40,
"Speed:");
656 String(this->
velocity).toCharArray(buf, 5);
657 u8g2->drawStr(60,40,buf);
658 }
while (
u8g2->nextPage() );
668 u8g2->drawBox(1, 1, 128, 12);
669 u8g2->drawBox(1, 48, 128, 68);
670 u8g2->setFontMode(0);
671 u8g2->setDrawColor(0);
672 u8g2->setFontDirection(0);
673 u8g2->setFont(u8g2_font_6x10_tf);
677 u8g2->drawXBM(110, 2, loop_width, loop_height, loop_bits);
681 u8g2->drawXBM(32, 50, play_width, play_height, play_bits);
682 u8g2->drawXBM(43, 51, tt_width, tt_height, stop_bits);
685 u8g2->drawStr(2,10,
"Pause");
688 u8g2->drawStr(45,10,
"PID ON");
692 u8g2->drawStr(45,10,
"PID OFF");
694 u8g2->setFontMode(1);
695 u8g2->setDrawColor(1);
696 u8g2->drawStr(2,35,
"Paused at pos");
697 String(index).toCharArray(buf, 3);
698 u8g2->drawStr(90,35,buf);
699 }
while (
u8g2->nextPage() );
708 if(btn->
state == DEPRESSED)
714 btn->
state = PRESSED;
723 else if((btn->
state == PRESSED) || (btn->
state == HOLD))
727 if(btn->
state != HOLD)
741 btn->
state = DEPRESSED;
750 if(btn->
state == HOLD)
752 if(btn->
time == HOLDTICK)
768 btn->
state = DEPRESSED;
void loop(void)
Contains the main logic of the shield functionality, e.g. transition between states (idle...
void playPage(bool loopMode, bool pidMode, uint8_t index, bool mode)
Holds the code for the play page of the OLED.
Watchdog timer interrupt handler, for examining the buttons periodically.
void recordMode(void)
Holds the record logic, showing the record page and recording positions from user input...
uStepper stepper
Creates an uStepper instance.
void changeVelocity(bool speedDirection=1)
Holds the code for the changing velocity during sequence play.
void idleMode(void)
Holds the idle logic; page to show, what buttons to enable etc.
void debounce(buttons *btn, uint8_t sample)
This function handles the debouncing and tracking of whether buttons are pressed, released or held...
void resetAllButton()
Resets the state of all 4 buttons at once.
volatile buttons recordBtn
void recordPage(bool pidMode, bool recorded, uint8_t index, float pos)
Holds the code for the record page of the OLED.
void idlePage(bool pidMode, float pos)
Holds the code for the idle page of the OLED.
Function prototypes and definitions for the egoShield library.
U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI * u8g2
void playMode(void)
Holds the play logic, showing play page and running the recorded sequence.
void pauseMode(void)
Holds the pause logic, showing the pause page and pausing the playing of a sequence.
void resetButton(buttons *btn)
Function for resetting the state of a button seperately.
void inputs(void)
Reads the four buttons and writes their value; no push, short push or long push, to global variables...
void startPage(void)
Holds the code for the start page of the OLED.
volatile buttons forwardBtn
void pausePage(bool loopMode, bool pidMode, uint8_t index)
Holds the code for the pause page of the OLED.
void WDT_vect(void) __attribute__((signal
volatile buttons backwardsBtn
egoShield(void)
Constructor of egoShield class.
void setup(uint16_t acc=1500, uint16_t vel=1000, uint8_t uStep=SIXTEEN, uint16_t fTol=10, uint16_t fHys=5, float P=1.0, float I=0.02, float D=0.006, float res=1)
Initializes buttons, OLED, uStepper and BT-module.