Introduction: ATMega1284 Bottle Boat

Picture of ATMega1284 Bottle Boat

Youtube Demonstratin Video

This device is a bottle boat that is powered by an ATMega1284 microcontroller, two DC motors, bluetooth control, a water level sensor, and an L293D motor driver. Another microcontroller may be used and will have many code differences. The body of the boat is made with household or recycled supplies that include ocean spray juice bottles, pencils, tape, hot glue, and a tupperware container. Also to note: this tutorial will be made under the assumption that you know how to program your microcontroller already.

GitHub

Here is the GitHub link to my folder. This is where you will find my code so that you can learn from and create this program for yourself. The header files are also super important, so make sure that you include them all in your project.

GitHub

References

The original idea for a bottle boat of this general form factor came from this instructable, and if you are using an arduino, this tutorial may be better suited for some of the aspects of the project. I was able to use this instructable to figure out the bluetooth module, however I included a step-by-step Windows 10 tutorial in this instructable.

AntiMicro(controller inputs for bluetooth, optional)

ATMega1284 Datasheet

L293D Datasheet

Also, I would like to thank my school's IEEE local branch for providing me with the supplies that I used to create this project including the ATMega1284 and the programmer for it. On top of that, I would like to thank my CS120B/CS122A professors at UCR for their informational labs which helped me to learn some of these components and for some of the foundational code.

Final words before we start

This set of instructions mainly focuses on the process of setting up and using the components, but not the very basic/foundational aspects of using this microcontroller. You can build this project with the supplies and code alone well enough, but if you are looking to add onto it you should know how to use the timer function, more state machines, etc.. If you have any questions about these things feel free to comment and I will do my best to direct you to resources or answer the questions you have.

Code

This is the code I used for the project. You can copy this in or use the project files found on GitHub, specifically in the Final project folder. There may be some copying related issues so I would recommend the GitHub files above all else.

<p>/*<br> *	Lab Section: 21
 *	Assignment: Custom Project
 *	Description: a boat made of bottles, tape, pencils, glue, and tupperware that is outfitted with electronic components including dc motors,
 *  a water level sensor, led lights, and a bluetooth module
 *	
 *	I acknowledge all content contained herein, excluding template or example
 *	code, is my own original work.
 *  Resources used/internet found code:</p><p> *  IEEE - Parts compilation used for the project
 *  CS 122A Instructors - information and foundational code
 *  <a href="https://github.com/AntiMicro/antimicro" rel="nofollow"> <a href="https://github.com/AntiMicro/antimicro" rel="nofollow">  https://github.com/AntiMicro/antimicro

</a>
</a>
 *  <a href="http://www.atmel.com/Images/Atmel-42718-ATmega1284_Datasheet.pdf" rel="nofollow"> <a href="https://github.com/AntiMicro/antimicro" rel="nofollow">  https://github.com/AntiMicro/antimicro

</a>
</a>
 *  <a href="http://www.ti.com/lit/ds/symlink/l293.pdf" rel="nofollow"> <a href="https://github.com/AntiMicro/antimicro" rel="nofollow">  https://github.com/AntiMicro/antimicro

</a>
</a>
 *  <a href="http://ttps//www.instructables.com/id/Make-a-robot-boat-from-water-bottles/" rel="nofollow"> <a href="https://github.com/AntiMicro/antimicro" rel="nofollow">  https://github.com/AntiMicro/antimicro

</a>
</a>
 *  <a href="https://www.instructables.com/id/AT-command-mode-of-HC-05-Bluetooth-module/" rel="nofollow"> <a href="https://github.com/AntiMicro/antimicro" rel="nofollow">  https://github.com/AntiMicro/antimicro

</a>
</a>
 */</p><p>#include <avr/io.h>
#include <usart_ATmega1284.h>
#include <avr/interrupt.h>
#include <io.c>
#include <io.h>
#include <timer.h></p><p>#include <queue.h></p><p>#include <bit.h><br></p><p>unsigned char check = 0x03;
static unsigned char i = 0;
unsigned char receivedData = 0x00;
unsigned char spider = 0x00;</p><p>unsigned int ADCvalfirst = 0;
unsigned int count = 0;
unsigned char speed;
unsigned char place = 1;
unsigned char Forward_Slow_Flag;
unsigned char leftnum = 0x01;
unsigned char rightnum = 0x04;
unsigned int ADCval = 0;
unsigned char ADCvalchar = 0x00;
unsigned int count_turn = 0;
unsigned char turn_flag = 0x00;
unsigned int pattern_count = 0;
unsigned int inside_count = 0;
unsigned int eight_count = 0;
unsigned char custom_flag = 0x00;
unsigned char onepattern = 0x00;
unsigned char twopattern = 0x00;
unsigned char threepattern = 0x00;
unsigned char fourpattern = 0x00;
unsigned char fivepattern = 0x00;
unsigned char sixpattern = 0x00;
unsigned char sevenpattern = 0x00;
unsigned char eightpattern = 0x00;
unsigned char pattern = 0x00;
unsigned int panic_count = 0;
//unsigned char decal = 0x00;</p><p>//Controls</p><p>// W is 0x67
// A is 0x61
// S is 0x63
// D is 0x64 DOESN'T WORK
// F is 0x66
// H is 0x68
//J is 0x6A
//K is 0x6B</p><p>typedef struct _task {
	/*Tasks should have members that include: state, period,
		a measurement of elapsed time, and a function pointer.*/
	signed char state; //Task's current state
	unsigned long int period; //Task period
	unsigned long int elapsedTime; //Time elapsed since last task tick
	int (*TickFct)(int); //Task tick function
} task;</p><p>enum SM1_States {One, Two, Three, Four, Forward_Slow, Turn_Slow, L63, Z7A, X78, V76, B62, N6E, M6D, Q71, W77, E65, R72, T74, Y79, U55, I69, P70} state;
	</p><p>int SM1_Tick(int state) {
	
	// Z7A, X78, V76, B62, N6E, M6D, Q71, W77, E65, R72, T74, Y79, U55, I69, P70
	// === Transitions ===
	
	switch (state) {
		case One:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = One;}
		break;
		
		case Two:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = Two;}
		break;
		
		case Three:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = Three;}
		break;
		
		case Four:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = Four;}
		break;
		
		case Forward_Slow:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = Forward_Slow;}
		break;
		
		case Turn_Slow:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = Turn_Slow;}
		break;
		
		case L63:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = L63;}
		break;
		
		
		
		case Z7A:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = Z7A;}
		break;
		
		case X78:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = X78;}
		break;
		
		case V76:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = V76;}
		break;
		
		case B62:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = B62;}
		break;
		
		case N6E:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = N6E;}
		break;
		
		
		case Q71:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = Q71;}
		break;
		
		case M6D:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = M6D;}
		break;
		
		
		
		
		case W77:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = W77;}
		break;
		
		case E65:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = E65;}
		break;
		
		
		
		case R72:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = R72;}
		break;
		
		case T74:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = T74;}
		break;
		
		
		
		case Y79:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = Y79;}
		break;
		
		case U55:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = U55;}
		break;
		
		
		
		case I69:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = I69;}
		break;
		
		case P70:
		if(panic_count >= 5000){state = Four;}
		else if(spider == 0x02 || spider == 0x63){state = One;}
		else if(spider == 0x61){state = Two;}
		else if(spider == 0x66) {state = Three;}
		else if(spider ==  0x67) {state = Four;}
		else if(spider == 0x68) {state = Forward_Slow;}
		else if(spider == 0x6A || spider == 0x6B) {state = Turn_Slow;}
		else if(spider == 0x6C){state = L63;}
		else if(spider == 0x7A){state = Z7A;}
		else if(spider == 0x78){state = X78;}
		else if(spider == 0x76){state = V76;}
		else if(spider == 0x62){state = B62;}
		else if(spider == 0x6E){state = N6E;}
		else if(spider == 0x6D){state = M6D;}
		else if(spider == 0x71){state = Q71;}
		else if(spider == 0x77){state = W77;}
		else if(spider == 0x65){state = E65;}
		else if(spider == 0x72){state = R72;}
		else if(spider == 0x74){state = T74;}
		else if(spider == 0x79){state = Y79;}
		else if(spider == 0x55){state = U55;}
		else if(spider == 0x69){state = I69;}
		else if(spider == 0x70){state = P70;}
		
		else{state = P70;}
		break;
		
		
		
		
		
		default:
		state = One;
		break;
		}
	</p><p>//========= Actions ===========//
	
	//Controls
	// A is 0x61
	// S is 0x63 doesn't work
	// D is 0x64
	// F is 0x66
	// G is 0x67
	// H is 0x68
	//J is 0x6A
	//K is 0x6B
	// L is 0x6C PATTERN 0x76
	// Z is 0x7A
	// X is 0x78
	//V is 0x56
	//B is 0x62
	//N is 0x6E
	//M is 0x6D
	//Q is 0x71
	//W is 0x77
	//E is 0x65
	//R is 0x72
	// T is 0x74
	// Y IS 0X79
	// U is 0x55
	//I is 0x69
	//P is 0x70
	//-----------------------------//
	//--------Water Values---------//
	//-------No water: 0x05--------// none
	//-------l water: 0x0D---------// low
	//-------m water: 0x35---------// medium
	//-------h water: 0x3E---------// high yellow!
	//-------P water: 0x46---------// panic!
	//-----------------------------//
	// L63, Z7A, X78, V76, B62, N6E, M6D, Q71, W77, E65, R72, T74, Y79, U55, I69, P70
	
	switch (state) {
	
		case One:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
	
		
	
		//-------------END------------//
		//PORTB = spider;
		PORTC = 0x00;
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		
		break;
		
		case Two:
		//------------BEGIN-----------// ADC Lights Code
		
		
	ADCval = ADC;
	if(ADCval <= 150)
	{
	if(spider == 0x73)
		{
		PORTB = 0x3C;
			}
		else
		{
		PORTB = 0x24;
			}
		
		}
	else if(ADCval <= 350)
	{
	if(spider == 0x73)
		{
		PORTB = 0x5A;
			}
		else
		{
		PORTB = 0x42;
			}
		}
	else if(ADCval <= 400)
	{
	if(spider == 0x73)
		{
		PORTB = 0x99;
			}
		else
		{
		PORTB = 0x81;
			}
		
		panic_count+=1;
		}
	else
	{
	if(spider == 0x73)
		{
		PORTB = 0x3C;
			}
		else
		{
		PORTB = 0x24;
			}
		}
	
	
		//-------------END------------//
		//PORTB = spider;
		PORTC = 0x01;
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		break;
		
		case Three:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
		//-------------END------------//
		//PORTB = spider;
		
		PORTC = 0x04;
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		break;
		
		case Four:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		//-------------END------------//
		//PORTB = spider;
		
		PORTC = 0x05;
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		break;
		
		case Forward_Slow:
		//------------BEGIN-----------// ADC Lights Code
		
		
	ADCval = ADC;
	if(ADCval <= 150)
	{
	if(spider == 0x73)
		{
		PORTB = 0x3C;
			}
		else
		{
		PORTB = 0x24;
			}
		
		}
	else if(ADCval <= 350)
	{
	if(spider == 0x73)
		{
		PORTB = 0x5A;
			}
		else
		{
		PORTB = 0x42;
			}
		}
	else if(ADCval <= 400)
	{
	if(spider == 0x73)
		{
		PORTB = 0x99;
			}
		else
		{
		PORTB = 0x81;
			}
		
		panic_count+=1;
		}
	else
	{
	if(spider == 0x73)
		{
		PORTB = 0x3C;
			}
		else
		{
		PORTB = 0x24;
			}
		}
	
	
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		if(count < 50)
		{
		if(Forward_Slow_Flag == 0x01){PORTC = 0x05;}
			else{PORTC = 0x00;}
			count++;
			}
		else if(count >= 50)
		{
		if(Forward_Slow_Flag == 0x01){Forward_Slow_Flag = 0x00;}
			else{Forward_Slow_Flag = 0x01;}
			count = 0;
			}
		
		break;
		
		
		case Turn_Slow:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		if(spider == 0x6A){turn_flag = 0x01;}
		else{turn_flag = 0x00;}
		if(count_turn < 200 && turn_flag == 0x01)
		{
		PORTC = 0x01;
			count_turn++;
			}
		else if(turn_flag == 0x01 && count_turn < 500)
		{
		PORTC = 0x05;
			count_turn++;
			}
		else if(count_turn < 200 && turn_flag == 0x00)
		{
		PORTC = 0x04;
			count_turn++;
			}
		else if(turn_flag == 0x00 && count_turn < 500)
		{
		PORTC = 0x05;
			count_turn++;
			}
		else{
		count_turn = 0;
			}
		break;
		
		case L63:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		
		if(pattern_count < 500)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 1000)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 1200)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 2000)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 2500)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 3000)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 3500)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 6000)
		{
		if(inside_count < 50)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else if(inside_count < 200)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		
		case Z7A:
		//------------BEGIN-----------// ADC Lights Code
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		
		if(pattern_count < 500)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 750)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 1000)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 1250)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 1500)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 1750)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 2000)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 3000)
		{
		if(inside_count < 50)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else if(inside_count < 200)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else
			{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 3250)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 3500)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 3750)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 4500)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		
		case X78:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		
		
		if(pattern_count < 500)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 500)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 1000)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 1500)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 2000)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 2500)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 3000)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 6000)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		
		case V76:
		//------------BEGIN-----------// ADC Lights Code
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		if(pattern_count < 250)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 500)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 1250)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 1500)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 1750)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 2200)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 3000)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 4000)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		
		case B62:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		
		if(pattern_count < 250)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 250)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 500)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 750)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 1000)
		{
		if(inside_count < 25)
			{
			PORTC = 0x04;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 2000)
		{
		if(inside_count < 25)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 3000)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		
		case N6E:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		if(pattern_count < 500)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 1000)
		{
		if(inside_count < 25)
			{
			PORTC = 0x04;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x01;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 1500)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 2000)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 2500){
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 3000)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 3500)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 4000)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else{
		pattern_count = 0;
			}
		break;
		
		case M6D:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		////PORTB = spider;
		if(pattern_count < 250)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 500)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 1250)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 1500)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 3000)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 4250)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 4500)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 5000)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		
		case Q71:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		if(pattern_count < 250)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 250)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 500)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 750)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 1000)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 2000)
		{
		if(inside_count < 25)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 3000)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		
		case W77:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		if(pattern_count < 250)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 250)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 500)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 750)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 1000)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 2000)
		{
		if(inside_count < 25)
			{
			PORTC = 0x04;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 3000)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		
		case E65:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		if(pattern_count < 250)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 250)
		{
		if(inside_count < 25)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x04;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 500)
		{
		if(inside_count < 25)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x01;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 750)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 1000)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 2000)
		{
		if(inside_count < 25)
			{
			PORTC = 0x04;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 3000)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		
		case R72:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		if(pattern_count < 500)
		{
		if(inside_count < 25)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 1000)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 1200)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 2000)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 2500)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 3000)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 3500)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else if(pattern_count < 6000)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		
		case T74:
		//------------BEGIN-----------// ADC Lights Code
		
		
	ADCval = ADC;
	if(ADCval <= 150)
	{
	if(spider == 0x73)
		{
		PORTB = 0x3C;
			}
		else
		{
		PORTB = 0x24;
			}
		
		}
	else if(ADCval <= 350)
	{
	if(spider == 0x73)
		{
		PORTB = 0x5A;
			}
		else
		{
		PORTB = 0x42;
			}
		}
	else if(ADCval <= 400)
	{
	if(spider == 0x73)
		{
		PORTB = 0x99;
			}
		else
		{
		PORTB = 0x81;
			}
		
		panic_count+=1;
		}
	else
	{
	if(spider == 0x73)
		{
		PORTB = 0x3C;
			}
		else
		{
		PORTB = 0x24;
			}
		}
	
	
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		if(pattern_count < 500)
		{
		if(inside_count < 25)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 1000)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 1200)
		{
		if(inside_count < 25)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 2000)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 2500)
		{
		if(inside_count < 25)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 3000)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 3500)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 6000)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		
		case Y79:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		
		if(pattern_count < 100)
		{
		if(inside_count < 25)
			{
			PORTC = 0x04;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 1500)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 2000)
		{
		if(inside_count < 25)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 2500)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 3000)
		{
		if(inside_count < 25)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x01;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 3500)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 4000)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		
		case U55:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		
		if(pattern_count < 100)
		{
		if(inside_count < 25)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x01;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 1500)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 2000)
		{
		if(inside_count < 25)
			{
			PORTC = 0x01;
				inside_count++;
				}
			else if(inside_count < 150)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 2250)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 2500)
		{
		if(inside_count < 50)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else if(inside_count < 100)
			{
			PORTC = 0x01;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 3500)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 3750)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		
		
		
		case I69:
		//------------BEGIN-----------// ADC Lights Code
		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		if(pattern_count < 400)
		{
		if(inside_count < 75)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else if(inside_count < 123)
			{
			PORTC = 0x01;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 1500)
		{
		PORTC = 0x00;
			pattern_count++;
			}
		else if(pattern_count < 1700)
		{
		if(inside_count < 50)
			{
			PORTC = 0x01;
				inside_count++;
				}
			else if(inside_count < 75)
			{
			PORTC = 0x04;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 2250)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 2500)
		{
		if(inside_count < 50)
			{
			PORTC = 0x01;
				inside_count++;
				}
			else if(inside_count < 100)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 3500)
		{
		PORTC = 0x05;
			pattern_count++;
			}
		else if(pattern_count < 3750)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		
		
		case P70:
		//------------BEGIN-----------// ADC Lights Code
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			
			}
		else if(ADCval <= 350)
		{
		if(spider == 0x73)
			{
			PORTB = 0x5A;
				}
			else
			{
			PORTB = 0x42;
				}
			}
		else if(ADCval <= 400)
		{
		if(spider == 0x73)
			{
			PORTB = 0x99;
				}
			else
			{
			PORTB = 0x81;
				}
			
			panic_count+=1;
			}
		else
		{
		if(spider == 0x73)
			{
			PORTB = 0x3C;
				}
			else
			{
			PORTB = 0x24;
				}
			}
		
		
		//-------------END------------//
		if(USART_HasReceived(0)){spider = USART_Receive(0);}
		//PORTB = spider;
		if(pattern_count < 400)
		{
		if(inside_count < 75)
			{
			PORTC = 0x01;
				inside_count++;
				}
			else if(inside_count < 123)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 1500)
		{
		if(inside_count < 50)
			{
			PORTC = 0x04;
				inside_count++;
				}
			else if(inside_count < 75)
			{
			PORTC = 0x01;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 1700)
		{
		if(inside_count < 50)
			{
			PORTC = 0x01;
				inside_count++;
				}
			else if(inside_count < 75)
			{
			PORTC = 0x05;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 2500)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 3000)
		{
		if(inside_count < 50)
			{
			PORTC = 0x01;
				inside_count++;
				}
			else if(inside_count < 100)
			{
			PORTC = 0x00;
				inside_count++;
				}
			else{inside_count = 0;}
			pattern_count++;
			}
		else if(pattern_count < 3700)
		{
		PORTC = 0x01;
			pattern_count++;
			}
		else if(pattern_count < 4050)
		{
		PORTC = 0x04;
			pattern_count++;
			}
		else{pattern_count = 0;}
		break;
		</p><p>default:
		break;
		
		// L63, Z7A, X78, V76, B62, N6E, M6D, Q71, W77, E65, R72, T74, Y79, U55, I69, P70
		
		}
	}</p><p>	//if(USART_HasReceived(0)){
	//PORTC = USART_Receive(0);
		</p><p>void ADC_init() {
ADCSRA |= (1 << ADEN) | (1 << ADSC) | (1 << ADATE);
	// ADEN: setting this bit enables analog-to-digital conversion.
	// ADSC: setting this bit starts the first conversion.
	// ADATE: setting this bit enables auto-triggering. Since we are
	//        in Free Running Mode, a new conversion will trigger whenever
	//        the previous conversion completes.
	}</p><p>int main(void)
{
 initUSART(0); // initializes USART0
	 DDRC = 0x1F; //
	 PORTC = 0x00; // Init port D to 0s
	 DDRA = 0x00;
	 PORTA = 0xFF;
	 DDRB = 0xFF; //0 is input, 1 is output
	 PORTB = 0x00;
	</p><p> 
	 ADC_init();
	 ADCval = ADC;
	 
	 ////Set_A2D_Pin(0x80);
	 
	 USART_Flush(0);
	 
	</p><p> 
	 
	
	    while (1) 
    {</p><p>		
		
		//Declare an array of tasks
		static task task1;
		task *tasks[] = {&task1};
		const unsigned short numTasks = sizeof(tasks)/sizeof(task*);
		// Task 1
		task1.state = One;//Task initial state.
		task1.period = 100;//Task Period.
		task1.elapsedTime = 100;//Task current elapsed time.
		task1.TickFct = &SM1_Tick;//Function pointer for the tick.
		
		TimerSet(1);
		TimerOn();
		
		
		for (int i = 0; i < numTasks; i++ ) {
		// Task is ready to tick
			if( tasks[i]->elapsedTime == tasks[i]->period ) {
			// Setting next state for task
				tasks[i]->state = tasks[i]->TickFct(tasks[i]->state);
				// Reset the elapsed time for next tick.
				tasks[i]->elapsedTime = 0;
				}
			tasks[i]->elapsedTime += 1;
			}
		
		
	
		
		while(!TimerFlag);
		TimerFlag = 0;
		</p><p>    }
}</p>

Step 1: Materials

Step 1: Materials
ATMega1284 Microcontroller($18.75)

ATMega1284 Programmer(~$40) - Not able to find link

Mini Solderless Breadboard 3PCs($8.99)

Colored jumper wires - Male to Male and Male to Female($7.99)

Breadboard Power Supply($1.86)

HC-06 Bluetooth Module($6.99)

DC Motors x2($6.21 each)

Propellers($7.99 for 12)

9V batteries($10 for 8)

L293D Motor Driver($8.99 for 10)

9 volt battery connector($8.95 for 10)

9 volt battery connector with barrel jack($6.99 for 10)

Water level sensor($6.99 for 5)

LEDs and Resistors were also used for the project Recycled or already owned materials used for the project included a tupperware container, hot glue tape, thumb tacks, scissors, and bottles

Not all of the components listed above were purchased for this particular project, but if someone were to build this project entirely with no prior components the above links contain the parts that they would need. Also, you can definitely use a different microcontoller for this project and if you're going to go with ATMEL microcontrollers, there are cheaper options. If you are using Arduino there are Arduino specific tutorials for these projects out there.

Step 2: Connect the Breadboard Power Supply and Programmer

  1. Add a capacitor between pins 10 and 11 and another between 30 and 31.
    1. Connect pins 10, 11, 32, and 30 to a 5V power supply - if you are using a breadboard terminal power supply just add wires between the terminal and the pins.
    2. Connect pins 11 and 31 to GND.Connect your programmer to pins 6, 7, 8, and 9 on the ATMega1284

If you are using a different programmer or microcontroller, these things may be different. Generally connect GND to ground and VREF/AVCC/VCC

Step 3: HC-06 Bluetooth Module

Picture of HC-06 Bluetooth Module

Power the HC-06

  1. Connect your module to a power supply and ground. If you look at the Fritzing diagram I included in this instructable, you can see that I achieved this with a breadboard power supply. You do not need to connect it to the microcontroller at this point. VCC and GND should be labeled on the device.
    1. Connect Vcc to 5V
    2. Connect GND to ground. If you connected the device to power and ground properly, your device should be blinking red.

Pair the HC-06

  1. Pair with the device. Go to bluetooth settings on your device by searching it in the menu and wait until you see "HC-06" and "ready to pair.
    1. Click pair
    2. If a password screen pops up, you should type in 1234 as this is the default password
    3. After this has been achieved, the device should say "paired"
  1. Assign COM Ports
    1. Scroll down to Related Settings on the bluetooth settings page and click "More bluetooth options"
    2. Select the COM Ports menu
    3. Click Add and then Click outgoing and select HC-06 from the drop down menu.
    4. Click OK.
    5. Record the COM Port that is labeled "Outgoing" - it will be useful later

TeraTerm

  1. Download TeraTerm
  2. Configure TeraTerm
    1. Open TeraTerm
    2. Click Serial
    3. Select the port that you assigned to "Outgoing" in the Assigning COM Ports step and click "Ok." If your device stops flashing, you've connected properly.
    4. To send data, just type any letter.

Connecting to the Microcontroller

  1. Connect the HC-06 module to the microcontroller.
    1. Connect the Tx Pin of the bluetooth module to the Rx pin of the microcontroller.
    2. Connect the Rx pin of the bluetooth module to the Tx pin of the microcontroller.

Code info

Here's how you include the USART header, which you can download from my Github page or elsewhere on the internet. You'll need to find another one for different microcontrollers.

#include<usart_ATmega1284.h> 

Now you can receive hex values from the HC-06.

unsigned char spider = 0x00;
<p>if(USART_HasReceived(0))</p>{
<p>spider = USART_Receive(0);</p>}

This is the example of USART code I will be using. You can find more information on the datasheet for the device your using. This is the one for the ATMega1284.

The data you receive that I have put into the unsigned char "spider" is a hex value. This corresponds to the hex value of the lowercase letter on the keyboard, which you can find here. For reference, A is 0x61, B is 0x62, etc.

You can use conditional statements based on the values received to implement controls.

Code that must be included in your main:

initUSART(0); // initializes USART0(USART will be used on RX0 and TX0

USART_Flush(0);

Step 4: Connect the L293D Motor Driver and Motors

Picture of Connect the L293D Motor Driver and Motors

I chose this motor driver for ease of use and support for what I need it. Here's the datasheet in case you want to check what is supports: L293D. That's also where you'll find the pin diagram.

  1. Connect L293D pins 1, 16, and 9 to each other. Connect pin 1 to the voltage source(5V)
  2. Connect L293D pins 4, 5, 12, and 13 to ground.
  3. Connect L293D pins to the ATMega1284
    1. L293D pin 7 to ATMega1284 pin PC0
    2. L293D pin 2 to ATMega1284 pin PC1
    3. L293D pin 10 to ATMega1284 pin PC2
    4. L293D pin 15 to ATMega1284 pin PC3
  4. Connect the first motor to L293D pins 3 and 6

  5. Connect the second motor to L293D pins 11 and 14

  6. Connect the positive end of your power supply(I used a 9V battery and the battery connector) to L293D pin 8 and the negative end to ground.

I would recommend soldering wires to the ends of the DC motors and connecting the wires to the appropriate pins. If you would like to test the motors you can connect the power supply directly to the motors. If you want to test the motors with the microcontroller, set PC0 to 0x01, 0x04, or 0x05. With the setup I directed, this will turn the motors on.

Step 5: Water Level Sensor

Picture of Water Level Sensor

The water level sensor I used is pretty standard A2D conversion. If you have ever used a photoresistor, you will have a similar experience with this. If you are using Arduino you can find the exact values using the serial monitor. If you are using an ATMega, I would recommend using a row of 8 LEDs and outputting the values to it or using and LCD screen and figuring out how to convert the values to a string that can be outputted. The values will be different so you will definitely have to collect your own.

ADC

  1. Connect your water level sensor to the first A2D pin of your ATMega1284(PA0).
  2. Add this function to your program to make sure that A2D will work.
void ADC_init() {<br>ADCSRA |= (1 << ADEN) | (1 << ADSC) | (1 << ADATE);
}

3. Add the code below to your main function before the while loop to initiate ADC. I used an unsigned int ADCval to get the values.

ADC_init();<br>ADCval = ADC;

Using the Code

I used the water level sensor to output to a row of LEDs based on whether or not the boat was above a certain water level. The code can be found below.

<p>//------------BEGIN-----------// ADC Lights Code<br>		
		
		ADCval = ADC;
		if(ADCval <= 150)
		{
			if(spider == 0x73)
			{
				PORTB = 0x3C;
			}
			else
			{
				PORTB = 0x24;
			}
			
		}
		else if(ADCval <= 350)
		{
			if(spider == 0x73)
			{
				PORTB = 0x5A;
			}
			else
			{
				PORTB = 0x42;
			}
		}
		else if(ADCval <= 400)
		{
			if(spider == 0x73)
			{
				PORTB = 0x99;
			}
			else
			{
				PORTB = 0x81;
			}
			
			panic_count+=1;
		}
		else
		{
			if(spider == 0x73)
			{
				PORTB = 0x3C;
			}
			else
			{
				PORTB = 0x24;
			}
		}
		
		
		//-------------END------------//</p>

My water level sensor only worked to about half way down, and 150, 350, and 400 were the values I found. I set the value of PORTB based on the values that I got - for example, if the amount was >= 400, the boat is sinking. I also added a panic function so that the boat takes actions if it reaches a panic_count of 5000 or more. The boat will go forward only and will no longer take user input as it tries to leave the body of water. This may be found in the code in the Github I linked in the introduction.

Step 6: Body and Arrangement of Components

Body

The body is definitely something I will leave up to you. I used 4 ocean spray bottles as the base attached to two airbags I got from an amazon package. I started with two of the ocean spray bottles but they did not float when the components were added, so I attempted to add two more bottles. When that was not enough, I added the airbags which made the boat float at the level I wanted to. I used pencils with hot glue to stabilize the bottles. I also used hot glue inside the lid to prevent the motors from moving around.

The motors were stuck inside of the neck, and holes were cut using pushpins and scissors in the actual lid. With this set up, the lid could still be twisted and sealed. I would recommend making a better seal for the motor, perhaps out of molding plastic as was done in other related tutorials to prevent water exposure.

To connect the wires to the tupperware container, I poked holes in the top of the bottles and threaded them through. I would recommend adding extra protection for these wires, or connecting them directly to the tupperware container. I poked holes in the lid of the container to thread the wires through to protect the electronic components from water exposure.

I connected the water level sensor to the outside of the boat with tape so that it extended to about 3/4 of the way down the tupperware container. You can modify this based on your interpretations of what sinking is.

The Electronics

This is the exact set up that I used with the boat. Cut off are the DC motors on the left and the other 9V battery on the right. I also modified this design in the end by changing the two middle LEDs on the strip of 8 with two buzzers, which I mentioned in the LDC section of the code. Since I did not modify the tone or any other factors of the buzzers, they were controllable in the exact same fashion as the LEDs - set the port it's on to 1, it makes noise, set it to 0, it's quiet.

Step 7: AntiMicro(Optional)

AntiMicro is a program that is used for mapping controllers which is usually used for video games. It can be used to map the inputs of a controller to any key on a keyboard, so I chose this for this project. You can also calibrate your own joysticks using a different microcontroller, but this method only needs the computer you have paired with the device and setup is simple.

Controls I used

With this, the left joystick is the full speed directions. Left will turn on the right motor which will make the device go left. Right will turn on the left motor which will make the device go right. Forward will turn on both motors. Back will turn off the motors.

The right joystick has gradual turns and slower forward. Forward is half speed. Left turns on the right motor full time and the left motor in bursts so the left turn is more gradual. Right turns on the left motor full time and and the right motors in bursts so that the right turn is more gradual. Backwards will it off.

The rest of the buttons are for preprogrammed patterns that I created which have different timings.

How to use it with TeraTerrm

Plug your controller in and map it as it is above. Save the layout for future use. Once you have mapped the device, open TeraTerm to the screen you use to send data to the bluetooth module and use the controller to send the values instead of the keyboard.

Comments

DIY Hacks and How Tos (author)2017-12-02

This sounds really cool. Do you have a video or pictures of this in action?

I added a link to the video at the top of the instructable!

About This Instructable

104views

2favorites

License:

More by Coulter_Mulvihill:ATMega1284 Bottle Boat
Add instructable to: