The Accelerometer: Software

Program Download:

Main C File

The Software
           The software for this tutorial is very straight forward. The 1 LED in the circuit blinks faster the more the sensor is tilted. In our case the sensor is on the breadboard, so we tilt the breadboard.

           Here is a snippet of the main loop in the program loop, keep in mind it uses the A/D converters to get the 'result' value:

------------« Begin Code »------------
	//Flash At The Determined Rate
PORTB = 0x00;
PORTB = 0x01;
	//Get A/D Converted Value
while( BusyADC() );
	result = ReadADC();
		//If Within Normal Range Blink Slowly
if(result > 506 && result < 518)
	flash = 200;
		//If Slightly Tilted Blink Faster
if(result > 518 && result < 550)
	flash = 100;
if(result > 545 && result < 506)
	lash = 100;
		//If Really Tilted Blink FAST!
if(result >= 550)
	flash = 25;
if(result <= 450)
	flash = 25;
------------« End Code »------------
The Code
           As you can see it is very simple, A/D converters are setup and input is taken. The input is evaluated and then the LED flashes appropriately (faster or slower). Now that your PIC is programmed with the software, let's see an example video of it in action!