Hi,
I'm putting together a machine based on a mega board.Everything is on the cheap with bits that I have lying around here, and the occasional piece from company scrap.. In addition, the machine's home location isn't somewhere where I would safely leave a PC.
I have had to work out some way of interfacing with the machine without using anything extravagant, nor without relying on a laptop.
To the effect, I have added the capability for 2 buttons, and 2 LED's (or one bi-colour).. Pin allocation is per the below constants.
The buttons are: Set Home, and Execute from SD (reads comm.txt command list)
The LEDs are Ready and Busy.
You will need to update the set home command to be suited to your own machine, or perhaps I will be more motivated and calculate it!
If anyone wants it, feel free.
Michael_Mod.ino
const int pinSetHome = 22;
const int pinExecFromSD = 24;
const int pinStatusReady = 23;
const int pinStatusBusy = 25;
int currentPSHState;
int currentPEFSDState;
void Michael_Init()
{
pinMode( pinSetHome, INPUT );
pinMode( pinExecFromSD, INPUT );
pinMode( pinStatusReady, OUTPUT );
pinMode( pinStatusBusy, OUTPUT );
currentPSHState = 0;
currentPEFSDState = 0;
}
void Michael_SetStatusBusy( int CurrentState )
{
if( CurrentState == 1 )
{
Serial.println( "MI - BUSY" );
digitalWrite( pinStatusBusy, HIGH );
digitalWrite( pinStatusReady, LOW );
}
else
{
Serial.println( "MI - READY" );
digitalWrite( pinStatusBusy, LOW );
digitalWrite( pinStatusReady, HIGH );
}
}
String Michael_Execute( String input )
{
// Execute command from SD =
// C34,comm.txt,END
int ButtonState = 0;
ButtonState = digitalRead( pinSetHome );
if ( ButtonState == HIGH )
{
currentPSHState = 1;
}
else
{
if ( currentPSHState == 1 )
{
Serial.println( "MI - PinSetHome released" );
currentPSHState = 0;
return "C09,3920,3920,END"; // Replace with the SetHome command parameters from controller app
}
}
ButtonState = 0;
ButtonState = digitalRead( pinExecFromSD );
if ( ButtonState == HIGH )
{
currentPEFSDState = 1;
}
else
{
if ( currentPEFSDState == 1 )
{
Serial.println( "MI - PinExecuteFromSD released" );
currentPEFSDState = 0;
return "C34,comm.txt,END"; // Requires comm.txt
}
}
return input;
}
comms.ino comms_waitForNextCommand
// and now read the command if one exists
// this also sets usingCrc AND commandConfirmed
// to true or false
inS = comms_readCommand();
inS = Michael_Execute( inS ); // Check button status
}
impl_mega.ino
void impl_executeCommand(String &com)
{
Michael_SetStatusBusy( 1 ); // Now busy
........ Original code!
else
{
comms_unrecognisedCommand(com);
comms_ready();
}
Michael_SetStatusBusy( 0 ); // Now Free
}
And of course the init code
void setup()
{
Michael_SetStatusBusy( 1 ); // Set bust light on - busy booting!
Serial.begin(57600); // set up Serial library at 57600 bps
Serial.print(F("POLARGRAPH ON!"));
Serial.println();
configuration_motorSetup();
eeprom_loadMachineSpecFromEeprom();
configuration_setup();
Michael_Init(); // Initialise button variables
..... original code here
delay(500);
outputAvailableMemory();
Michael_SetStatusBusy( 0 ); // Ready
}
|