This is first run, just one direction and speed switching :) very simple code
#include <avr/io.h>
#include <stdint.h>
int __attribute__ ((section (".noinit"))) speed;
int main (void) {
DDRB = 0b0111; // all out
PORTB = 0b0000;
speed=speed+4;
if ((speed > 20)||(speed < 1))
{
speed=5;
}
while (1)
{
PORTB = 0b0001;
wait();
PORTB = 0b0011;
wait();
PORTB = 0b0010;
wait();
PORTB = 0b0110;
wait();
PORTB = 0b0100;
wait();
PORTB = 0b0101;
wait();
}
}
void wait ()
{
delay (speed);
PORTB = 0b0000;
}
void delay (int millis) {
for (volatile unsigned int i = 34*millis; i>0; i--);
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.