Save programming time when you start new Arduino projects.
Modify your BareMinimum.ino file which is a template for new programs.
When you use File/New in your IDE, this is the template that is presented.
There is one problem: Windows won't let you edit any file in that folder (or any other folder in C:\Program Files (x86)). You have to move the file to - for example - C:\Temp, edit it and then move it back! And don't try to start the IDE or create a new project in the mean time, the IDE will crash.
Erik_Baas:
Nope. I could not save it, in spite of being logged in as administrator. (Windows 7/64)
I just got it done like this:
Windows assumed
Create new file. It'll be named sketch
Modify as desired and save it in the user folder and close
Navigate to the user folder and to the folder containing the newly created .ino file
Copy the .ino file.
Navigate to the bare minimum folder as illustrated above
Paste your new custom file to the folder
Rename the existing bareMinimum, I used 'BareMinimum orig'
Rename the new file to BareMinimum
Done
It's probably worth adding that on Mac the file is replaced every time you upgrade the IDE so if the changes are non-trivial it might be worth keeping a backup copy somewhere outside the Arduino.app package.
Here is one of my many basic skeleton sketches that I start with.
I delete the things not need, then proceed with adding new stuff.
// Name.ino
// Web Link
//********************************************^************************************************
// Version YY/MM/DD Description
// 1.00 YY/MM/DD Running sketch
//
//
//********************************************^************************************************
//Diagnostic Macros
// Atmega328/UNO
// =============
// PINB D8 to D13
// D8=0x01 D9=0x02 D10=0x04 D11=0x08 D12=0x10 D13=0x20
// PINB0 PINB1 PINB2 PINB3 PINB4 PINB5
//62.5ns delay
#define NOOP asm("nop\n")
#define diagnostics
#ifdef diagnostics
#define PULSE63_13 cli(); PINB = bit(PINB5); PINB = bit(PINB5); sei()
#define PULSE126_13 cli(); PINB = bit(PINB5); NOOP; PINB = bit(PINB5); sei()
#define PULSE189_13 cli(); PINB = bit(PINB5); NOOP; NOOP; PINB = bit(PINB5); sei()
#define PULSE252_13 cli(); PINB = bit(PINB5); NOOP; NOOP; NOOP; PINB = bit(PINB5); sei()
#define PULSE315_13 cli(); PINB = bit(PINB5); NOOP; NOOP; NOOP; NOOP; PINB = bit(PINB5); sei()
#define PULSE378_13 cli(); PINB = bit(PINB5); NOOP; NOOP; NOOP; NOOP; NOOP; PINB = bit(PINB5); sei()
#else
#define PULSE63_13 //Not defined
#define PULSE126_13 //Not defined
#define PULSE189_13 //Not defined
#define PULSE252_13 //Not defined
#define PULSE315_13 //Not defined
#define PULSE378_13 //Not defined
#endif
//********************************************^************************************************
//Serial or parallel LCD
#define serialLCDisBeingUsed //uncomment if you have a serial LCD <-----<<<<<
#ifdef serialLCDisBeingUsed
#include <Wire.h>
//Use I2C library: https://github.com/duinoWitchery/hd44780
//LCD Reference: https://www.arduino.cc/en/Reference/LiquidCrystal
#include <hd44780.h> //main hd44780 header
//NOTE:
//hd44780_I2Cexp control LCD using I2C I/O expander backpack (PCF8574 or MCP23008)
//hd44780_I2Clcd control LCD with native I2C interface (PCF2116, PCF2119x, etc...)
#include <hd44780ioClass/hd44780_I2Cexp.h> //I2C expander i/o class header
//If you do not know what your I2C address is, first run the 'I2C_Scanner' sketch
//OR
//Run: I2CexpDiag.ino
//C:\Users\YourName\Documents\Arduino1.69\libraries\hd44780\examples\ioClass\hd44780_I2Cexp\I2CexpDiag
//LCD I2C address
//hd44780_I2Cexp lcd(0x3F);
hd44780_I2Cexp lcd(0x27);
//********************************************
#else
#include <LiquidCrystal.h>
// LCD pin 4 6 11 12 13 14
// RS EN D4 D5 D6 D7
LiquidCrystal lcd(12, 11, 4, 5, 6, 7);
#endif
//********************************************^************************************************
#define CLOSED LOW
#define OPENED HIGH
#define PUSHED LOW
#define RELEASED HIGH
#define LEDon HIGH
#define LEDoff LOW
#define RELAYon LOW
#define RELAYoff HIGH
#define RUNNING true
#define notRUNNING false
#define ENABLED true
#define DISABLED false
//********************************************^************************************************
const byte buttonPin = 2; // +5V---[50k Pullup]---[Input Pin]---[Switch]---GND
const byte heartbeatLED = 13; // +5V----[220R]----[A->|-K]----GND
//LCD uses 12, 11, 7, 6, 5 and 4
bool stateMachineFlag = RUNNING;
byte lastButtonPinState = RELEASED;
//****************************
//timing stuff
unsigned long heartbeatTime;
unsigned long stateMachineTime;
unsigned long switchTime;
const unsigned long toggleInterval = 500ul; //500ms
//****************************
//State Machine
enum States {Startup, State1, State2, State3, State4, State5};
States mState = Startup;
//****************************
//LCD geometry
const byte LCD_COLS = 16;
const byte LCD_ROWS = 4;
#define LCD_20X4
//#define LCD_16X2
// s e t u p ( )
//********************************************^************************************************
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT_PULLUP); // +5V---[50k Pullup]---[Input Pin]---[Switch]---GND
pinMode(heartbeatLED, OUTPUT);
//****************************
//LCD stuff
#ifdef LCD_20X4
lcd.begin(20, 4);
#else
lcd.begin(LCD_COLS, LCD_ROWS);
#endif
//lcd.noBlink();
//lcd.noCursor();
//lcd.noBacklight();
//lcd.backlight();
lcd.clear();
//****************************
lcd.setCursor(0, 1);
// 111111
// 0123456789012345
lcd.print(" Hello World ");
} //END of setup()
// l o o p ( )
//********************************************^************************************************
void loop()
{
//PULSE378_13;
//************************************* heartbeat T I M E R
//to see if the sketch has blocking code,
//toggle the heartbeat LED (every 500ms)
if (millis() - heartbeatTime >= toggleInterval)
{
//restart the TIMER
heartbeatTime = millis();
//toggle the LED
digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
}
//************************************* switch T I M E R
//is it time to check the switches ? (every 50ms)
if (millis() - switchTime >= 50ul)
{
//PULSE378_13;
//restart the TIMER
switchTime = millis();
//go and check the switches
checkSwitches();
}
//************************************* checkMachine T I M E R
//if its running, is it time to check the the State Machine ?
if (stateMachineFlag == RUNNING && millis() - stateMachineTime >= 1ul)
{
//PULSE378_13;
//restart this TIMER
stateMachineTime = millis();
//service the State Machine
checkMachine();
}
//*********************************
//other non blocking code goes here
//*********************************
} //END of loop()
// c h e c k S w i t c h e s ( )
//********************************************^************************************************
void checkSwitches()
{
//************************************* buttonPin
//buttonPin code
byte currentState = digitalRead(buttonPin);
//*****************************
//was there a change in state ?
if (lastButtonPinState != currentState)
{
//update to the new state
lastButtonPinState = currentState;
//*************
//was the switch closed ?
if (currentState == CLOSED)
{
//switch was CLOSED
}
//*************
//switch was OPENED
else
{
}
} //END of this switch
} //END of checkSwitches()
// c h e c k M a c h i n e ( )
//********************************************^************************************************
//checking to see if the State Machine needs servicing
void checkMachine()
{
switch (mState)
{
//********************** Startup
case Startup:
{
}
break;
//END of case
//********************** State1
case State1:
{
}
break;
//END of case
//********************** State2
case State2:
{
}
break;
//END of case
//********************** State3
case State3:
{
}
break;
//END of case
//********************** State4
case State4:
{
}
break;
//END of case
//********************** State5
case State5:
{
}
break;
//END of case
} //END of switch/cases
} //END of checkMachine()
//********************************************^************************************************