Close

Attiny10 source code :D

A project log for Ant highway - linear motor for micro cars

Small magic pcb for moving miniature cars, trains or satellites :-)

bobriciusbobricius 04/14/2019 at 14:320 Comments

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