Giter Site home page Giter Site logo

arduino-kitt-scanner's People

Contributors

mi-schi avatar

Watchers

 avatar  avatar

arduino-kitt-scanner's Issues

Code is to huge for Attiny24

First try to have all functions minimized for Attiny24:

byte lightPins[8] = {5, 4, 3, 1, 0, 8, 9, 10};
byte allLights[8] = {0, 1, 2, 3, 4, 5, 6, 7};
byte halfLights[2][4] = {{0, 1, 2, 3}, {4, 5, 6, 7}};
byte lights[3][4][2] = {
  {{0, 7}, {1, 6}, {2, 5}, {3, 4}},
  {{0, 4}, {1, 5}, {2, 6}, {3, 7}},
  {{3, 4}, {2, 5}, {1, 6}, {0, 7}}
};
byte speedPin = A6;
volatile byte program = 0;

void setup() {
  for (int i=0; i<8; i++) {
    pinMode(lightPins[i], OUTPUT);
  }  
  pinMode(2, INPUT);
  attachInterrupt(1, programSwitch, RISING);
}

void loop() {
  if (program == 1) {
    // flasher
    flasher();
  } else if (program == 2 || program == 3) {
    // police 2 times, police
    for (byte s = 0; s < 2; s++) {
      toogleHalfLights(s);
      if (program == 3) {
        toogleHalfLights(s);
      }
    }
  } else if (program == 5 || program == 6 || program == 7 || program == 11 || program == 12) {
    // out to in splitted/full, left to right splitted, in to out splitted/full
    lightsToMidFull(lights[program-5]);
  } else if (program == 13) {
    // left to right two lights
    byte l[4] = {0, 1, 6, 7};
    twoLeds(l, 1, 7);
  } else if (program == 14) {
    // right to left two lights
    byte l[4] = {7, 6, 1, 0};
    twoLeds(l, 6, 0);
  } else if (program == 8) {
    // flasher 2 times
    flasher();
    sensoredDelay();
    flasher();
  } else if (program == 9) {
    // snake
    snake(0, 7);
  } else if (program == 10) {
    // snake reverse
    snake(7, 0);
  } else {
    kitt(0, 7);
    kitt(7, 0);
  }
}

void kitt(byte start, byte end) {
  for (int i=start; i<end; i++) {
    digitalWrite(lightPins[i], HIGH);
    sensoredDelay();
    digitalWrite(lightPins[i+1], HIGH);
    sensoredDelay();
    digitalWrite(lightPins[i], LOW);
    sensoredDelay();
  }
}

void twoLeds(byte sL[4], byte start, byte end) {
    digitalWrite(lightPins[sL[0]], 1);
    sensoredDelay();
    digitalWrite(lightPins[sL[1]], 1);
    sensoredDelay();
    for (int i=start; i<end; i++) {
      digitalWrite(lightPins[i-1], 0);
      digitalWrite(lightPins[i], 1);
      digitalWrite(lightPins[i+1], 1);
      sensoredDelay();
    }
    digitalWrite(lightPins[sL[6]], 0);
    sensoredDelay();
    digitalWrite(lightPins[sL[7]], 0);
    sensoredDelay();
}

void snake(byte s, byte e) {
    for (int i=s; i<=e; i++) {
      digitalWrite(lightPins[i], 1);
      sensoredDelay();
    }
    for (int i=e; i<=s; i++) {
      digitalWrite(lightPins[i], 0);
      sensoredDelay();
    }
}

void toogleHalfLights(byte s) {
  for (byte i = 0; i < 2; i++) {
    switchLights(halfLights[s], i);
    sensoredDelay();
  }
}

void lightsToMidFull(byte lights[4][2]) {
  byte maxI = 4;
  if (program < 10) {
    maxI = 3;
  }
  for (int i=0; i<maxI; i++) {
    switchLights(lights[i], HIGH);
    sensoredDelay();
    if (program < 10) {
      switchLights(lights[i], LOW);
    }
  } 
  for (int i=maxI; i>0; i--) {
    switchLights(lights[i], HIGH);
    sensoredDelay();
    if (program < 10) {
      switchLights(lights[i], LOW);
    }
  }
}

void flasher() {
    switchLights(allLights, 1);
    sensoredDelay();
    switchLights(allLights, 0);
    sensoredDelay();
}

void switchLights(byte lights[], byte value) {
  for (byte i = 0; i < (sizeof(lights)/sizeof(int)); i++) {
    digitalWrite(lightPins[lights[i]], value);
  }
}

void sensoredDelay() {
  delay(analogRead(speedPin) + 50);
}

void programSwitch() {
  program++;
  if (program == 16) {
    program = 0;
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.