79 u8g2 =
new U8G2_SSD1306_128X64_NONAME_1_4W_SW_SPI(U8G2_R0, 11, 9, U8X8_PIN_NONE, 2, 10);
82 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, uint16_t
shutterDelay)
88 WDTCSR = (1 << WDCE) | (1 << WDE);
89 WDTCSR |= (1 << WDIE) | (1 << WDE);
117 u8g2->setFontMode(1);
118 u8g2->setDrawColor(1);
119 u8g2->setFontDirection(0);
120 u8g2->setFont(u8g2_font_6x10_tf);
122 u8g2->drawStr(2,10,
"Magnet not present !");
123 }
while (
u8g2->nextPage() );
125 while(
stepper.encoder.detectMagnet() == 2 ||
stepper.encoder.detectMagnet() == 1);
132 pinMode(
FWBT ,INPUT);
133 pinMode(
PLBT ,INPUT);
134 pinMode(
RECBT ,INPUT);
135 pinMode(
BWBT ,INPUT);
136 pinMode(
OPTO,OUTPUT);
137 digitalWrite(
OPTO ,HIGH);
138 digitalWrite(
FWBT ,HIGH);
139 digitalWrite(
PLBT ,HIGH);
140 digitalWrite(
RECBT ,HIGH);
141 digitalWrite(
BWBT ,HIGH);
149 while(
stepper.getMotorState());
180 static bool continousForward = 0;
181 static bool continousBackwards = 0;
187 if(this->forwardBtn.
state != HOLD)
190 continousForward = 0;
193 else if(continousBackwards)
195 if(this->backwardsBtn.
state != HOLD)
198 continousBackwards = 0;
201 if(this->playBtn.
btn)
203 while(this->playBtn.
state == PRESSED);
204 if(this->playBtn.
state == DEPRESSED)
207 continousForward = 0;
208 continousBackwards = 0;
225 while(this->playBtn.
state == HOLD);
229 else if(this->forwardBtn.
btn)
231 if(this->forwardBtn.
state == HOLD)
233 if(!continousForward)
236 continousForward = 1;
238 this->forwardBtn.
btn = 0;
243 this->forwardBtn.
btn = 0;
246 else if(this->backwardsBtn.
btn)
248 if(this->backwardsBtn.
state == HOLD)
250 if(!continousBackwards)
253 continousBackwards = 1;
255 this->backwardsBtn.
btn = 0;
260 this->backwardsBtn.
btn = 0;
263 else if(this->recordBtn.
btn == 1)
266 continousForward = 0;
267 continousBackwards = 0;
274 static uint8_t started = 0;
278 if(this->recordBtn.
btn)
280 while(this->recordBtn.
state == PRESSED);
281 if(this->recordBtn.
state == DEPRESSED)
293 else if(this->playBtn.
btn)
295 while(this->playBtn.
state == PRESSED);
296 if(this->playBtn.
state == DEPRESSED)
307 while(this->playBtn.
state == HOLD);
333 if(this->forwardBtn.
state == HOLD)
338 else if(this->backwardsBtn.
state == HOLD)
350 if(this->forwardBtn.
btn == 1 && this->velocity <= 9900 && this->acceleration <= 19900)
352 this->forwardBtn.
btn = 0;
356 else if(this->backwardsBtn.
btn == 1 && this->velocity >= 200 && this->acceleration >= 200)
358 this->backwardsBtn.
btn = 0;
362 else if(this->playBtn.
btn == 1)
375 if(this->playBtn.
btn)
377 while(this->playBtn.
state == PRESSED);
378 if(this->playBtn.
state == DEPRESSED)
386 while(this->playBtn.
state == HOLD);
395 static uint8_t step = 0;
396 static uint32_t i = 0, j = 0;
397 static uint8_t runState = 0;
402 digitalWrite(
OPTO, HIGH);
405 this->forwardBtn.
btn = 0;
408 else if(this->backwardsBtn.
btn == 1 &&
stepSize >= 0.25)
410 this->backwardsBtn.
btn = 0;
413 else if(this->recordBtn.
btn == 1)
416 this->recordBtn.
btn = 0;
424 this->forwardBtn.
btn = 0;
427 else if(this->backwardsBtn.
btn == 1 &&
interval >= (500 + this->shutterDelay))
429 this->backwardsBtn.
btn = 0;
432 else if(this->recordBtn.
btn == 1)
435 this->recordBtn.
btn = 0;
441 if(this->playBtn.
btn)
443 while(this->playBtn.
state == PRESSED);
444 if(this->playBtn.
state == DEPRESSED)
469 else if(runState == 1)
478 else if(runState == 2)
482 digitalWrite(
OPTO, LOW);
488 else if(runState == 3)
490 if(((millis() - j) > 200))
492 digitalWrite(
OPTO, HIGH);
497 else if(runState == 4)
505 if(this->playBtn.
btn == 1)
516 while(
stepper.getMotorState());
528 this->
debounce(&forwardBtn,(PINC >> 3) & 0x01);
529 this->
debounce(&playBtn,(PINC >> 1) & 0x01);
530 this->
debounce(&recordBtn,(PINC >> 2) & 0x01);
531 this->
debounce(&backwardsBtn,(PINC >> 0) & 0x01);
538 u8g2->drawXBM(19, 20, logo_width, logo_height, logo_bits);
539 }
while (
u8g2->nextPage() );
550 sBuf.toCharArray(buf, 20);
554 u8g2->drawBox(1, 1, 128, 12);
555 u8g2->drawBox(1, 48, 128, 68);
556 u8g2->setFontMode(0);
557 u8g2->setDrawColor(0);
558 u8g2->setFontDirection(0);
559 u8g2->setFont(u8g2_font_6x10_tf);
562 u8g2->drawXBM(5, 51, en_width, en_height, bw_bits);
563 u8g2->drawXBM(112, 51, en_width, en_height, fw_bits);
564 u8g2->drawXBM(32, 50, play_width, play_height, play_bits);
565 u8g2->drawXBM(43, 51, tt_width, tt_height, stop_bits);
566 u8g2->drawXBM(71, 51, tt_width, tt_height, rec_bits);
567 u8g2->drawXBM(85, 51, tt_width, tt_height, pse_bits);
570 u8g2->drawStr(2,10,
"Idle");
573 u8g2->drawStr(45,10,
"PID ON");
577 u8g2->drawStr(45,10,
"PID OFF");
579 u8g2->setFontMode(1);
580 u8g2->setDrawColor(1);
581 u8g2->drawStr(2,35,buf);
582 }
while (
u8g2->nextPage() );
593 u8g2->drawBox(1, 1, 128, 12);
594 u8g2->drawBox(1, 48, 128, 68);
595 u8g2->setFontMode(0);
596 u8g2->setDrawColor(0);
597 u8g2->setFontDirection(0);
598 u8g2->setFont(u8g2_font_6x10_tf);
600 u8g2->drawXBM(5, 51, en_width, en_height, bw_bits);
601 u8g2->drawXBM(112, 51, en_width, en_height, fw_bits);
602 u8g2->drawXBM(38, 51, tt_width, tt_height, stop_bits);
603 u8g2->drawXBM(76, 51, tt_width, tt_height, rec_bits);
606 u8g2->drawStr(2,10,
"Record");
609 u8g2->drawStr(45,10,
"PID ON");
613 u8g2->drawStr(45,10,
"PID OFF");
615 u8g2->setFontMode(1);
616 u8g2->setDrawColor(1);
622 sBuf.toCharArray(buf, 22);
623 u8g2->drawStr(2,35,buf);
628 sBuf += (int32_t)pos;
630 sBuf.toCharArray(buf, 22);
631 u8g2->drawStr(2,35,buf);
633 }
while (
u8g2->nextPage() );
643 u8g2->drawBox(1, 1, 128, 12);
644 u8g2->drawBox(1, 48, 128, 68);
645 u8g2->setFontMode(0);
646 u8g2->setDrawColor(0);
647 u8g2->setFontDirection(0);
648 u8g2->setFont(u8g2_font_6x10_tf);
652 u8g2->drawXBM(110, 2, loop_width, loop_height, loop_bits);
656 u8g2->drawXBM(5, 51, en_width, en_height, bw_bits);
657 u8g2->drawXBM(112, 51, en_width, en_height, fw_bits);
658 u8g2->drawXBM(32, 50, play_width, play_height, play_bits);
659 u8g2->drawXBM(43, 51, tt_width, tt_height, stop_bits);
660 u8g2->drawXBM(77, 51, tt_width, tt_height, pse_bits);
663 u8g2->drawStr(2,10,
"Play");
666 u8g2->drawStr(45,10,
"PID ON");
670 u8g2->drawStr(45,10,
"PID OFF");
672 u8g2->setFontMode(1);
673 u8g2->setDrawColor(1);
676 u8g2->drawStr(2,25,
"Adjust velocity");
680 u8g2->drawStr(2,25,
"Moving to pos");
681 String(index).toCharArray(buf, 5);
682 u8g2->drawStr(90,25,buf);
684 u8g2->drawStr(2,40,
"Speed:");
685 String(this->
velocity).toCharArray(buf, 5);
686 u8g2->drawStr(60,40,buf);
687 }
while (
u8g2->nextPage() );
697 u8g2->drawBox(1, 1, 128, 12);
698 u8g2->drawBox(1, 48, 128, 68);
699 u8g2->setFontMode(0);
700 u8g2->setDrawColor(0);
701 u8g2->setFontDirection(0);
702 u8g2->setFont(u8g2_font_6x10_tf);
706 u8g2->drawXBM(110, 2, loop_width, loop_height, loop_bits);
710 u8g2->drawXBM(32, 50, play_width, play_height, play_bits);
711 u8g2->drawXBM(43, 51, tt_width, tt_height, stop_bits);
714 u8g2->drawStr(2,10,
"Pause");
717 u8g2->drawStr(45,10,
"PID ON");
721 u8g2->drawStr(45,10,
"PID OFF");
723 u8g2->setFontMode(1);
724 u8g2->setDrawColor(1);
725 u8g2->drawStr(2,35,
"Paused at pos");
726 String(index).toCharArray(buf, 3);
727 u8g2->drawStr(90,35,buf);
728 }
while (
u8g2->nextPage() );
740 u8g2->drawBox(1, 1, 128, 12);
741 u8g2->drawBox(1, 48, 128, 68);
742 u8g2->setFontMode(0);
743 u8g2->setDrawColor(0);
744 u8g2->setFontDirection(0);
745 u8g2->setFont(u8g2_font_6x10_tf);
748 u8g2->drawXBM(5, 51, en_width, en_height, bw_bits);
749 u8g2->drawXBM(112, 51, en_width, en_height, fw_bits);
750 u8g2->drawXBM(76, 51, tt_width, tt_height, rec_bits);
751 u8g2->setFontMode(1);
752 u8g2->setDrawColor(1);
753 u8g2->drawStr(115,24,
"<-");
754 u8g2->setFontMode(0);
755 u8g2->setDrawColor(0);
759 u8g2->drawXBM(5, 51, en_width, en_height, bw_bits);
760 u8g2->drawXBM(112, 51, en_width, en_height, fw_bits);
761 u8g2->drawXBM(76, 51, tt_width, tt_height, rec_bits);
762 u8g2->setFontMode(1);
763 u8g2->setDrawColor(1);
764 u8g2->drawStr(115,34,
"<-");
765 u8g2->setFontMode(0);
766 u8g2->setDrawColor(0);
770 u8g2->drawXBM(32, 50, play_width, play_height, play_bits);
771 u8g2->drawXBM(38, 51, tt_width, tt_height, stop_bits);
775 u8g2->drawXBM(38, 51, tt_width, tt_height, stop_bits);
778 u8g2->drawStr(2,10,
"Time");
781 u8g2->drawStr(45,10,
"PID ON");
785 u8g2->drawStr(45,10,
"PID OFF");
787 u8g2->setFontMode(1);
788 u8g2->setDrawColor(1);
792 sBuf.toCharArray(buf, 22);
793 u8g2->drawStr(2,24,buf);
797 sBuf.toCharArray(buf, 22);
798 u8g2->drawStr(2,34,buf);
802 sBuf.toCharArray(buf, 22);
803 u8g2->drawStr(2,44,buf);
804 }
while (
u8g2->nextPage() );
809 if(btn->
state == DEPRESSED)
815 btn->
state = PRESSED;
824 else if((btn->
state == PRESSED) || (btn->
state == HOLD))
828 if(btn->
state != HOLD)
842 btn->
state = DEPRESSED;
851 if(btn->
state == HOLD)
853 if(btn->
time == HOLDTICK)
869 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.
uStepper stepper
Creates an uStepper instance.
void WDT_vect(void) __attribute__((signal
Watchdog timer interrupt handler, for examining the buttons periodically.
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.
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.
void timeMode(void)
Holds the timelapse logic, showing the timelapse page.
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 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, uint16_t shutterDelay=250)
Initializes buttons, OLED, uStepper and BT-module.
void resetButton(buttons *btn)
Function for resetting the state of a button seperately.
Function prototypes and definitions for the egoShield library.
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.
void pausePage(bool loopMode, bool pidMode, uint8_t index)
Holds the code for the pause page of the OLED.
void changeVelocity(void)
Holds the code for the changing velocity during sequence play.
void timePage(uint8_t step, bool pidMode)
Holds the code for the timelapse page of the OLED.
egoShield(void)
Constructor of egoShield class.