Here is sketch with adjustable timeing
// Initialising screen:
#define TITLE_LINE_1 " Bedini-O "
#define TITLE_LINE_2 " 1.0 by Rawbush "
////////////////////////////////////////////////////////////////////////////////
// Includes
#include <stdlib.h>
#include <stdio.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <LCD4Bit_mod.h> // The library files <LCD4Bit_mod.h> can be found here:
// http://www.nuelectronics.com
#include <Wire.h> // include Wire library for I2C
#include <EEPROM.h> // for persistent system state
#include <Button.h> // http://www.arduino.cc/playground/Code/Button
///////////////////////////////////////////////////////////////////////////////////////////
// FUNCTION TEMPLATES: //
// //
// This is a Template taken directly from arduino.cc/playground/Code/EEPROMWriteAnything //
// This creates two functions that will allow us to save 'Confiuration' data. The data //
// will be stored in a Structure that will contain ALL of the values that we use so //
// that there is only one 'Save' and one 'Read' required. //
///////////////////////////////////////////////////////////////////////////////////////////
template <class T> int EEPROM_writeAnything(int ee, const T& value)
{
const byte* p = (const byte*)(const void*)&value;
int i = 0;
for (i = 0; i < sizeof(value); i++)
EEPROM.write(ee++, *p++);
return i;
}
template <class T> int EEPROM_readAnything(int ee, T& value)
{
byte* p = (byte*)(void*)&value;
int i = 0;
for (i = 0; i < sizeof(value); i++)
*p++ = EEPROM.read(ee++);
return i;
}
// END FUNCTION TEMPLATES:
////////////////////////////////////////////////
// Macros //
////////////////////////////////////////////////
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
///////////////////////////////////////////////////////////////////////
// Constants: //
// This is where you would setup, add or change some Default values //
///////////////////////////////////////////////////////////////////////
Button Trig1 = Button (15,PULLUP); // sets analog pin 0 as Trig-1 input, also pulled up
Button Trig2 = Button (16, PULLUP); // sets analog pin 1 as Trig-2 input, also pulled up
const int Drive1 = 17; // sets analog pin 2 as Drive-1 output
const int Drive2 = 18; // sets analog pin 3 as Drive-2 output
const int MIN_D1D1 = 0; // Drive-1/Delay-1 min delay time in ms
const int MAX_D1D1 = 10; //Drive-1/Delay-1 max delay time in ms
const int MIN_D1D2 = 0; // Drive-1/Delay-2 min delay time in ms
const int MAX_D1D2 = 10; //Drive-1/Delay-2 max delay time in ms
const int MIN_D2D1 = 0; // Drive-2/Delay-1 min delay time in ms
const int MAX_D2D1 = 10; //Drive-2/Delay-1 max delay time in ms
const int MIN_D2D2 = 0; // Drive-2/Delay-2 min delay time in ms
const int MAX_D2D2 = 10; //Drive-2/Delay-2 max delay time in ms
const int LCD_WIDTH = 16; // just some values for the 2 line 16 char display
const int LCD_HEIGHT = 2;
const int NUM_CURSOR_POSITIONS = LCD_WIDTH; // sets the number of cursor positions
const int MS_SCREEN_RESTART = 5000; //used to restart the LCD to get out of screwups
/////////////////////////////////////////////////////////////////////////////////
// These next set of variables are used as a small lookup table. The cursor //
// will be setting at a position on the display from 0-15. Depending on which //
// Menu item we are wanting to change/modify we will 'Look' at this table for //
// the correct muliplier at the given Cursor position. //
/////////////////////////////////////////////////////////////////////////////////
const long aDelayMultipliers[NUM_CURSOR_POSITIONS] = {
0,0,0,0,0,0,0,0,0,0,0,0,10,1,0,0}; //Delay multipliers
const long alSaveButtonEmulator[NUM_CURSOR_POSITIONS] = {
0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0};//only position 4 is use. set 1 wil save settings to eeprom
////////////////////////////////////////////////////
// Menu Items: //
// Add and 'Definition' of new menu itens here. //
///////////////////////////////////////////////////
enum MENU_ITEMS
{
MENU_SOFT_RPM = 0, // Will be used later to display RPM
MENU_SOFT_D1D1 = 1, // Drive-1/Delay-1 this is used to retard timing
MENU_SOFT_D1D2 = 2, // This is the amount of time the Drive-1 is pulsed ON in ms
MENU_SOFT_D2D1 = 3, // Drive-2/Delay-1 this is used to retard timing
MENU_SOFT_D2D2 = 4, // This is the amount of time the Drive-2 is pulsed ON in ms
MENU_SAVE_OPTS = 5, // Save All the option settings
MENU_NUM_ITEMS = 6, //always last one on the 'MENU_ITEMS' stack
};
///////////////////////////////////////////////////////////////////////////////////
// Set some static values for Current Sensor, Frequency and Duty Cycle. //
// NOTE: Static values are values that do not change unless forced to. //
///////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////
// Variables: //
////////////////////////////////////////////////////
int iMenuSelect = 0; //use to select each menu item
int RPM; //RPM
int D1D1; //Drive-1 Delay-1
int D1D2; //Drive-1 Delay-2
int D2D1; //Drive-2 Delay-1
int D2D2; //Drive-2 Delay-2
int iSaveSettingVal[1];// Force a write to eeprom of all the current settings.
int iCursorPosition; //the current cursor position
bool bCursorUp; // state of the bottom line cursor
bool bRedrawLine1; // set true whenever you want the LCD to refresh line1
bool bRedrawLine2; // set true whenever you want the LCD to refresh line2
bool UseFcnPWM;
/////////////////////////////////////////////////////
// Set up the IO, A/D and PWM pins on the Arduino //
/////////////////////////////////////////////////////
long previousMillis = 0; // will store last Delay Time
long previousRefresh = 0; // will store last Display Refresh Time
///////////////////////////////////////////////////////////////////////////
// STRUCTURES: //
// //
// This structure will contain ALL of the parameter and variables //
// that we will want to maintain in a consistant state even if the //
// Arduino is powered off. This Strucure can contain as many elements //
// as we desire and we can Add to it at any time. The Item in the //
// structure must caontain item of the same TYPE that we are using for //
// a given 'Option'. Example: if we define a variable/option as a LONG //
// then we must have a cooresponding element in the structure define as //
// a LONG as well. //
// //
// NOTE: The current structure is just a place holder for the moment-RRB //
///////////////////////////////////////////////////////////////////////////
struct config_t
{
///////////////////////////////////////////////////////////////////////
// Please note: it is ok to use the same name here because these are //
// Outside the 'Regular Scope' of the main program. It is nice //
// because it make it easier to 'Match' up with a cooresponding //
// Value/variable. //
///////////////////////////////////////////////////////////////////////
int D1D1; //Drive-1 Delay-1
int D1D2; //Drive-1 Delay-2
int D2D1; //Drive-2 Delay-1
int D2D2; //Drive-2 Delay-2
} configuration;
//END STRUCTURES:
//////////////////////////////////////////////////////////////////
// Objects: //
//////////////////////////////////////////////////////////////////
LCD4Bit_mod lcd = LCD4Bit_mod(LCD_HEIGHT);//LCD handling object
///////////////////////////////////////////////////////
// Initialise //
///////////////////////////////////////////////////////
void setup()
{
////////////////////////////////////////
// start serial port Added by AllGood //
////////////////////////////////////////
Serial.begin(9600);
UseFcnPWM = true;
//Set Drive pins
pinMode (17, OUTPUT); // this is output for Drive-1
pinMode (18, OUTPUT); // this is output for Drive-2
continues on next post