ԀI˥ℲOᙠᴚ∩⊥
🔍

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;
     }
     
};
Related Posts
Basic touch helpers for ESP32
Basic touch helpers for ESP32

Here is an example of basic usage for the helper functions. // ---------------------------------- // -------MAIN LOOP ----------------- // ---------------------------------- Read more

Basic LED helper for Arduino & ESP32
Basic LED helper for Arduino & ESP32

Arduino LED Helpers Simply create an LED object from the helper functions to handle fading, pulsing or manual call of Read more

textile touch matrix 3×3

Code for Processing/Java and ESP32/C++ Both code work with the ESP32 connected via USB. import processing.serial.*; int t1_val = Read more

microcontrolled sound
microcontrolled sound

TEENSY SYNTH https://www.youtube.com/watch?v=UJcZxyB5rVc !!! https://www.pjrc.com/teensy/gui/?info=AudioOutputAnalog# http://www.ralfschreiber.com/solarsound/solarsound.html