an electronics badge exercise


selection of basic components besides cables and Arduino


illustrated visual preview of the complete badge without Arduino connectors


illustrated circuit done with Fritzing


preview of a lasercutted badge with wooden material (cut & burn)


both cut and burn map (splitted for visual reasons)

lasercut prototype on wood

SOLDERING

BASIC ARDUINO CODE

This example does flash the LED constantly while pressing the button fades out the LED smoothly.

// ----------------------------------
// -------- MAIN LOOP  --------
// ----------------------------------
 
int buttonpin = 0;
 
// setup the LED object  aLED namewhatever(pin);
aLED led1(11);
 
void setup() {
   pinMode(buttonpin,INPUT);
}
 
void loop() {
  
  led1.operateLED(); //operate specific LED

   int buttonval = analogRead(buttonpin);
  if(buttonval>0){
     led1.setMode(2);
     led1.fade_target = 0;
     led1.fade_speed = 16;
     
   }else{
      led1.setMode(1);
      led1.pulse_speed = .09;
   }

   
  delay(20);
}
 
// ----------------------------------
// -------- BASIC LED HELPER --------
// ----------------------------------
 
// basic lerp function
float return_lerp(float _s, int _target,int _time){
   _s = _s + (( float(_target) - _s)/float(_time));
   return _s;
     
}
 
// --------------
// LED Object
// -------------
 class aLED {
  private:
    byte pin;
    long ts = 0;
    int led_mode = 0; //0 manual / 1:sinpulse / 2:fading
     
    
   public:
   int brightness = 0; // current brightness
   float fade_target = 0; // where to fade?
   int fade_speed = 4; 
   float pulse_speed = .004; // speed of pulse when in pulsemode
   int pulse_amplitude = 125;
     
    aLED(byte pin) {
     this->pin = pin;
     init();
    } 
 
    void init(){
        pinMode(pin,OUTPUT);
    }
 
    void operateLED(){
        if(led_mode==0){ 
 
        // if in manual mode
          
        }else if(led_mode==1){
           
          // -----------  PULSE MODE
          brightness =  int((sin(millis()*pulse_speed)+1)*pulse_amplitude*.5);
           
        }else if(led_mode==2){
           
          // -----------  FADING MODE
         brightness = int(return_lerp(brightness,fade_target,fade_speed));
 
        }
       
      analogWrite(pin,brightness);
 
     
    }
 
    void setMode(int _mode){
        led_mode = _mode;
     }
     
};