Squirrels have fuzzy tails.
0 Members and 1 Guest are viewing this topic.
while(1) servo_left(35);
/*********ADD YOUR CODE BELOW THIS LINE **********/ LED_on();//turn LED on while(1) { servo_left(35); /* //store sensor data sensor_left=a2dConvert8bit(5); sensor_right=a2dConvert8bit(4); //detects more light on left side of robot if(sensor_left > sensor_right && (sensor_left - sensor_right) > threshold) {//go left servo_left(44); servo_right(44); } //detects more light on right side of robot else if(sensor_right > sensor_left && (sensor_right - sensor_left) > threshold) {//go right servo_left(25); servo_right(25); } //light is about equal on both sides else {//go straight servo_left(25); servo_right(44); } */ /* Servo Test Code i=250; while(i>0) { servo_left(40); i--; } i=250; while(i>0) { servo_left(24); i--; } */ //rprintf("Initialization Complete\r\n"); //output message to serial (use hyperterminal) //print("Hello, World! Read My Analog: %u\r\n", sensor_0); delay_cycles(500);//a small delay to prevent crazy oscillations } /*********ADD YOUR CODE ABOVE THIS LINE **********/
/*********ADD YOUR CODE BELOW THIS LINE **********/ LED_on();//turn LED on while(1) { while(1) servo_left(35); /* //store sensor data sensor_left=a2dConvert8bit(5); sensor_right=a2dConvert8bit(4);
/****************************************************************************** Copyright (c) 2007 www.societyofrobots.com* (please link back if you use this code!)** This program is free software; you can redistribute it and/or modify* it under the terms of the GNU General Public License version 2 as* published by the Free Software Foundation.** Alternatively, this software may be distributed under the terms of BSD* license.** Photovore v1, March 10th, 2007* Simple case-based method for a robot that chases light.******************************************************************************///AVR includes#include <avr/io.h> // include I/O definitions (port names, pin names, etc)#include <avr/interrupt.h> // include interrupt support//AVRlib includes#include "global.h" // include global settings#include "a2d.h" // include A/D converter function library//define port functions; example: PORT_ON( PORTD, 6);#define PORT_ON( port_letter, number ) port_letter |= (1<<number)#define PORT_OFF( port_letter, number ) port_letter &= ~(1<<number)//************CONFIGURE PORTS************//configure ports for input or output - specific to ATmega8void configure_ports(void) { DDRC = 0x00; //configure all C ports for input PORTC = 0x00; //make sure pull-up resistors are turned off DDRD = 0xFF; //configure all D ports for output DDRB = 0xC7; //configure B ports 0, 1, 2, 6, 7 for output (google search '0b11000111 to hex') }//***************************************//************DELAY FUNCTIONS************//wait for X amount of cycles (23 cycles is about .992 milliseconds)//to calculate: 23/.992*(time in milliseconds) = number of cyclesvoid delay_cycles(unsigned long int cycles) { while(cycles > 0) cycles--; }//***************************************//*********SIMPLIFIED FUNCTIONS**********//functions to make coding easier for a beginner//but could cause port mixup confusion for intermediate usersvoid LED_on(void) { PORT_OFF(PORTD, 4);//turn LED on }void LED_off(void) { PORT_ON(PORTD, 4);//turn LED off }void servo_left(signed long int speed) { PORT_ON(PORTD, 0); //delay_cycles(speed); PORT_OFF(PORTD, 0);//keep off //delay_cycles(200); }void servo_right(signed long int speed) { PORT_ON(PORTD, 1); //delay_cycles(speed); PORT_OFF(PORTD, 1);//keep off //delay_cycles(200); }//***************************************int main(void) { //declare variables here /*********ADD YOUR CODE BELOW THIS LINE **********/ LED_on();//turn LED on while(1) { while(1) servo_left(35); //rprintf("Initialization Complete\r\n"); //output message to serial (use hyperterminal) //print("Hello, World! Read My Analog: %u\r\n", sensor_0); delay_cycles(500);//a small delay to prevent crazy oscillations } /*********ADD YOUR CODE ABOVE THIS LINE **********/ return 0; }/*********************COMMAND LIST*************************delay_cycles(cycles);Delays - you can make your robot wait for a certain amount of time with this function.Put the number of computational cycles to delay in the ().23 cycles is about .992 millisecondsto calculate: 23/.992*(time in milliseconds to delay) = cyclesCheck servo datasheet where it says: 'Direction: Clockwise/Pulse Traveling 1500 to 1900usec'servo_left(speed); and servo_right(speed);Commands your servos to rotate at a certain speed.Vary speed (which represents a delay in cycles) from 20 to 50.Left is for port D0 and right is for port D1.LED_on(); and LED_off();Turns on and off your LED. The LED is on port D4.By bringing port D4 low, you are turning on the LED.variable=a2dConvert8bit(pin);Reads analog pin. For example, set 'pin' to 5 to read PC5.'variable' will store the value.***********************************************************/