Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
#include "sys/atmega8.h"#include <motorPWM.h>#include "a2d.h"// Define two light sensors connected to ADC channels 4 and 5#define sensorLeft ADC_NUMBER_TO_CHANNEL(5)#define sensorRight ADC_NUMBER_TO_CHANNEL(4)// Define two motorsMOTOR left = MAKE_MOTOR_3_PIN(FALSE, D0,D1,D2);MOTOR right = MAKE_MOTOR_3_PIN(TRUE , D3,D4,D5);// Create the list - remember to place an & at the// start of each servo nameMOTOR_LIST motors[] = {&left,&right};// Create a driver for the list of motorsMOTOR_DRIVER bank1 = MAKE_MOTOR_DRIVER(motors);//the larger this number, the more likely your robot will drive straight#define threshold 8// In my initialising code - pass the list of motors to controlvoid appInitHardware(void){// Initialise the motor controllermotorL293Init(&bank1);// Give each servo a start value of 'stop'act_setSpeed(&left, 0);act_setSpeed(&right,0);}TICK_COUNT appInitSoftware(TICK_COUNT loopStart){return 0;}// This is the main loopTICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart){uint8_t lightLeft = a2dConvert8bit(sensorLeft);uint8_t lightRight = a2dConvert8bit(sensorRight);if(lightLeft > lightRight && (lightLeft - lightRight) > threshold){// go leftact_setSpeed(&left,DRIVE_SPEED_MIN);act_setSpeed(&right,DRIVE_SPEED_MAX);}else if(lightRight > lightLeft && (lightRight - lightLeft) > threshold){// go rightact_setSpeed(&left,DRIVE_SPEED_MAX);act_setSpeed(&right,DRIVE_SPEED_MIN);}else{// Go forwardsact_setSpeed(&left,DRIVE_SPEED_MAX);act_setSpeed(&right,DRIVE_SPEED_MAX);}return 20000; // wait for 20ms to stop crazy oscillations}
...is it not possible to run l293d on a atmega 8 or is my code poorly written and taking unnecessary space ?...