Skip to content

Commit

Permalink
Reverse button works; minor UI movements
Browse files Browse the repository at this point in the history
  • Loading branch information
gniezen committed Sep 2, 2014
1 parent 8c4adb8 commit a3a4f6d
Showing 1 changed file with 54 additions and 49 deletions.
103 changes: 54 additions & 49 deletions ui/ui.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ long positionRight = -999;
long timeBetweenSteps = 1000; // in ms
long previousMillis = 0;

boolean running = false;
boolean running, reversing = false;

void setup()
{
Expand All @@ -37,8 +37,7 @@ void setup()

void loop()
{
Serial.begin(9600);

// Read rotary encoder
long newLeft, newRight;
newLeft = knobLeft.read();
newRight = knobRight.read();
Expand All @@ -60,94 +59,100 @@ void loop()

positionLeft = newLeft;
positionRight = newRight;

//sprintf(buff, "%ld.%ld", newLeft/2, newRight/2);
//Serial.println(buff);

}

//Drive stepper motor

digitalWrite(dirpin, HIGH); // Set the direction.
if(reversing) {
digitalWrite(dirpin, LOW); // Set the direction backward

for(int i=0;i<1000;i++) {
digitalWrite(steppin, LOW);
delayMicroseconds(2); //motor speed
digitalWrite(steppin, HIGH); // Creates 'rising edge'
delayMicroseconds(1000); //motor speed
}
}

unsigned long currentMillis = millis();
if(running) {
if(running && !reversing) {

digitalWrite(dirpin, HIGH); // Set the direction forward

if(currentMillis - previousMillis > (timeBetweenSteps-positionLeft)) {
// save the last time you blinked the LED

previousMillis = currentMillis;

for (int i = 0; i<10; i++) // number of microsteps at one time
for (int i = 0; i<20; i++) // number of microsteps at one time
{
digitalWrite(steppin, LOW);
digitalWrite(steppin, LOW);
delayMicroseconds(2);
digitalWrite(steppin, HIGH); // Creates 'rising edge'
delayMicroseconds(500); //motor speed
delayMicroseconds(1000); //motor speed
}
}
}

// Graphics

//GD.ClearColorRGB(0x103000);

GD.get_inputs();
GD.Clear();
//GD.cmd_text(240, 68, 31, OPT_RIGHTX, buff);
//GD.cmd_text(240, 75, 28, OPT_,"mL/hr");
plotRate(100,68,positionLeft/2,positionRight/2);

/*
GD.Begin(POINTS); // draw 50-pixel wide green circles
GD.ColorRGB(20, 91, 71);
GD.PointSize(50 * 16);
GD.BlendFunc(SRC_ALPHA, ONE);
// additive blending
for (int x = 100; x <= 380; x += 40)
GD.Vertex2ii(x, 200);
*/

plotRate(110,68,positionLeft/2,positionRight/2);

//GD.cmd_button(20,150,190,50,28,OPT_FLAT,"Button");

GD.Begin(BITMAPS);
/*
GD.Vertex2ii(240, 110, SPINNER_HANDLE, i);
i += 1;
if(i>11)
i = 0;
*/
//GD.cmd_spinner(50,50,1,0);

//GD.Vertex2ii(240,110,GREY_PANEL_HANDLE);

pressed = GD.inputs.tag;

int offset1, offset2=0;
int offset1, offset2,offset3=0;

//Start button
GD.Tag(1);
if(pressed == 1) {
GD.Vertex2ii(20,174,BUTTON1_HANDLE);
GD.Vertex2ii(70,174,BUTTON1_HANDLE);
offset1=4;
running = true;
}else{
GD.Vertex2ii(20,170,BUTTON0_HANDLE);
GD.Vertex2ii(70,170,BUTTON0_HANDLE);
offset1=0;
}
GD.Vertex2ii(35,175+offset1,START_HANDLE);
GD.cmd_text(140,175+offset1, 31, OPT_CENTERX,"Start");
GD.Vertex2ii(85,175+offset1,START_HANDLE);
GD.cmd_text(185,185+offset1, 29, OPT_CENTERX,"Start");

//Stop button
GD.Tag(2);
GD.ColorRGB(0xff2e18);
if(pressed == 2) {
GD.Vertex2ii(230,174,BUTTON1_HANDLE);
GD.Vertex2ii(280,174,BUTTON1_HANDLE);
offset2=4;
running = false;
}else{
GD.Vertex2ii(230,170,BUTTON0_HANDLE);
GD.Vertex2ii(280,170,BUTTON0_HANDLE);
offset2=0;
}
GD.ColorRGB(0xffffff);
GD.Vertex2ii(245,175+offset2,STOP_HANDLE);
GD.cmd_text(345, 175+offset2, 31, OPT_CENTERX,"Stop");
GD.Vertex2ii(295,175+offset2,STOP_HANDLE);
GD.cmd_text(395, 185+offset2, 29, OPT_CENTERX,"Stop");

//Reverse button
GD.Tag(3);
GD.ColorRGB(0x0000ff);
if(pressed == 3) {
GD.Vertex2ii(280,34,BUTTON1_HANDLE);
offset3=4;
reversing = true;
}else{
GD.Vertex2ii(280,30,BUTTON0_HANDLE);
offset3=0;
reversing=false;
}
GD.ColorRGB(0xffffff);
GD.cmd_text(370, 45+offset3, 29, OPT_CENTERX,"Reverse");

if(running)
GD.cmd_spinner(240,136,1,0);
GD.cmd_spinner(130,110,1,0);

GD.swap();
}
Expand All @@ -156,11 +161,11 @@ static void plotRate(int x, int y, int decimal, int fractional)
{
int font = 31;

GD.cmd_text(x,y-25,font-4,OPT_CENTER,"Rate:");
GD.cmd_text(x,y-30,font-4,OPT_CENTER,"Rate:");
GD.cmd_number(x - 8, y, font, OPT_RIGHTX | OPT_CENTERY, decimal);
//GD.cmd_text( x, y, font, 0 | OPT_CENTERY, ".");

GD.cmd_number(x + 8, y, font, 2 | OPT_CENTERY, fractional);
GD.cmd_number(x + 8, y, font-1, 2 | OPT_CENTERY, fractional);
GD.cmd_text(x+60, y, font-2,OPT_CENTERY, "mL/hr");

GD.PointSize(16 * 5); // means 30 pixels
Expand Down

0 comments on commit a3a4f6d

Please sign in to comment.