Close

The Tiberium Code

A project log for Artificial Tiberium Cluster

Who doesn't want to have a Tiberium Cluster at his/her Place? ;-)

stefan-xpStefan-Xp 02/19/2017 at 14:410 Comments
So since i didn't avance in Mechanics, at least i have my desired Code.

Find it here below.

// Tiberium Sketch
// This sketch will fade a LED in and out ("breathing")
// SW PWM for Atmega16
// 2017-02-19 Stefan-Xp

int LED_Pin = A6;       // Pin Number of the desired LED Output
int Periode = 10000;    // in µs, so the PWM will have ~100Hz
int OnTime = Periode;   // Ontime, determines how bright a LED will appear
int Step = 40;          // Stepsize, determines how fast the Transistion will be

void setup() {
  // Initialise LED Pin
  pinMode(LED_Pin, OUTPUT);
}

void loop() {
  // Set to On
  digitalWrite(LED_Pin, LOW);
  // Wait the Time which the LED should stay on
  delayMicroseconds(OnTime);
  // Set to Off
  digitalWrite(LED_Pin, HIGH);
  // Wait the remeining Time of the Cycle
  delayMicroseconds(Periode - OnTime);
  
  // Determine if the Stepdirection should be changed 
  // (>= Period Time (100%) or below 30%)
  if(OnTime + Step >= Periode || OnTime <= Periode*0.30)
    Step = -Step;
    
  // Increase / Decrease OnTime
  OnTime += Step;
}
It is pretty simple. Sorry if you are Disappointed :-/

Have a nice Sunday!

Discussions