Nick Stanley
Published © GPL3+

Jack and Coke Bot

Pour the perfect Jack and Coke every time.

BeginnerShowcase (no instructions)8 hours957
Jack and Coke Bot

Things used in this project

Hardware components

NXP HCS08
×1
Solenoid Valve
×2
General Purpose Transistor NPN
General Purpose Transistor NPN
×2
LM2937 Voltage Regulator
×1
Capacitor 10 µF
Capacitor 10 µF
×1
Capacitor 100 nF
Capacitor 100 nF
×1

Story

Read more

Schematics

Schematic

Code

main.c

C/C++
#include "mc9s08qg8.h" /* include peripheral declarations */

#define ButtonSingle PTAD_PTAD0   //Button on port A0
#define ButtonDouble PTAD_PTAD1   //Button on port A1
#define ShotOpen PTBD_PTBD5 //Shot on port B5
#define CokeOpen PTBD_PTBD4 //Coke on port B4
//Timing (TO BE DONE)
const int TIME_SHOT = 558;
const int TIME_COKE = 2 * TIME_SHOT;
const int WAIT = 200;
const int MULTIPLY = 1000;
int i, j;
int Pouring; //So it doesnt double pour if button held down
//Pour Together
void PourJackAndCokeSimul(void)
{
  //Keep both open
  for(j = 0; j < TIME_SHOT; ++j) 
  {
    for(i = 0; i < MULTIPLY; ++i)
    {
      ShotOpen = 1;
      CokeOpen = 1;
    }
  }
  //Close shot
  ShotOpen = 0;
  //Keep Coke open
  for (j = 0; j < TIME_COKE; ++j) 
  {
    for(i = 0; i < MULTIPLY; ++i)
    {
      CokeOpen = 1;
    }
  }
  //Close coke
  CokeOpen = 0;  
}
void PourJackAndCokeDouble(void)
{
  //Keep both open
  for(j = 0; j < 837; ++j) 
  {
    for(i = 0; i < MULTIPLY; ++i)
    {
      ShotOpen = 1;
      CokeOpen = 1;
    }
  }
  //Close shot
  ShotOpen = 0;
  //Keep Coke open
  for (j = 0; j < 837; ++j) 
  {
    for(i = 0; i < MULTIPLY; ++i)
    {
      CokeOpen = 1;
    }
  }
  //Close coke
  CokeOpen = 0;
}
 
//Entry Point
void main(void) 
{     
  SOPT1 = SOPT1_BKGDPE_MASK+SOPT1_RSTPE_MASK;
  ICSTRM = NV_ICSTRM;  
  for (i=0;i<400;i++); /* delay 2 ms (at 4 MHz) */  
  ICSC2 = 0;  /* up speed to 8 MHz */
    
  //Configure Port A0 for Single Input (active low)
  PTADD_PTADD0 = 0;
  PTAPE_PTAPE0 = 1;
  //Configure Port A1 for Double Input (active low)
  PTADD_PTADD1 = 0;
  PTAPE_PTAPE1 = 1;
  //Configure Ports B4 & B5 for Output
  PTBDD_PTBDD5 = 1;
  PTBDD_PTBDD4 = 1;
   
  while (1)
  {
    if (!Pouring) 
    {      
      if (ButtonSingle == 0) //Active low is less glitchy 
      {
        Pouring = 1;      
        PourJackAndCokeSimul();
        while(ButtonSingle == 0) //wait for button to be released
        {
          CokeOpen = 0;
          ShotOpen = 0;
        }
        Pouring = 0;
        for (j = 0; j < 837; ++j) 
        {
          for(i = 0; i < MULTIPLY; ++i);
        }
      }
      if (ButtonDouble == 0)
      { 
        Pouring = 1;     
        PourJackAndCokeDouble();
        while(ButtonDouble == 0)
        {
          CokeOpen = 0;
          ShotOpen = 0;
        }
        Pouring = 0;
        for (j = 0; j < 837; ++j) 
        {
          for(i = 0; i < MULTIPLY; ++i);
        } 
      }
    }
  }
}

Credits

Nick Stanley

Nick Stanley

5 projects • 13 followers
Software Engineer - System Integrator - Maker of Things
Thanks to David Rose.

Comments