Example Projects

Circuits and Code Wireless

Meet the Materials
Conductive Materials
Non-Conductive Materials
Thinking Out Loud
Circuits and Code
  • Arduino Overview
  • Arduino as Bluetooth HID
  • ATtiny: 7-Segment Display
  • ATtiny: Capacitive Sensing
  • ATtiny: Programming
  • ATtiny Serial & Wireless Boards!
  • ATtiny: Soft Serial
  • ATtiny: Sound
  • ATtiny: Soft Fade
  • Bits and Bytes Binary numbers
  • Multiplexed Matrix
  • Controlling EL Panel and EL Wire
  • EL panel/wire inverter hack
  • EMF amplifier
  • Heat Controlling Circuit
  • LED with Light Sensor
  • Lilypad XBee Shield
  • My First Arduino Connection Check
  • pressure matrix code + circuit
  • Pull-up Resistors
  • Rabbit Control Client on Bela
  • RabbitControl on Bela
  • RGB Colour Fade
  • simple heat circuit
  • Solar Powered Motor Circuit
  • Sound Amplifying Circuits
  • Graphing and Drawing Sensor Values
  • Teensy as HID Device
  • Transistor Switch
  • Volume Detection
  • Visualization: 2x2 Matrix
  • Visualization: Drawing
  • Visualization: Graph
  • Visualization: Pressure Sensor Matrix
  • Visualization: Touchpad
  • Voltage Divider
  • Voltage Divider with Arduino
  • What is Variables?
  • Support the creation of content on this website through PATREON!
  • About
  • E-Textile Events
  • E-Textile Spaces
  • Newsletter
  • Print & Publications
  • E-Textile Shopping

    Content by Mika Satomi and Hannah Perner-Wilson
    E-Textile Tailor Shop by KOBAKANT
    The following institutions have funded our research and supported our work:

    Since 2020, Hannah is guest professor of the Spiel&&Objekt Master's program at the University of Performing Arts Ernst Busch in Berlin

    From 2013-2015 Mika was a guest professor at the eLab at Kunsthochschule Berlin-Weissensee

    From July - December 2013 Hannah was a researcher at the UdK's Design Research Lab

    From 2010-2012 Mika was a guest researcher in the Smart Textiles Design Lab at The Swedish School of Textiles

    From 2009 - 2011 Hannah was a graduate student in the MIT Media Lab's High-Low Tech research group led by Leah Buechley

    In 2009 Hannah and Mika were both research fellows at the Distance Lab

    Between 2003 - 2009 Hannah and Mika were both students at Interface Cultures
    We support the Open Source Hardware movement. All our own designs published on this website are released under the Free Cultural Works definition
    Circuits and Code

    ATtiny: Soft Fade

    PWM (“analog output”) on all five i/o pins of an ATtiny using software PWM!

    The software PWM code was written by Ernst Christensen, I found it in the following Arduino forum thread:
    >> http://arduino.cc/forum/index.php/topic,75334.0.html

    Example of fabric circuit using software PWM code >> http://www.kobakant.at/DIY/?p=3395

    My slightly edited version of Ernst’s code:

    // code for ATtiny
    // fades LEDs on all five pins on and off using software PWM

    #define fadeSpeed 20
    void setup(){
    for(int pin=0;pin<5;pin++) pinMode(pin, OUTPUT); } void loop(){ for(int pin=0;pin<5;pin++) { for(int fade=1;fade<254;fade++) { //fade on softPWM(pin, fade, fadeSpeed); } for(int fade=254;fade>1;fade–) { //fade off
    softPWM(pin, fade, fadeSpeed);
    void softPWM(int pin, int freq, int sp) { // software PWM function that fakes analog output
    digitalWrite(pin,HIGH); //on
    digitalWrite(pin,LOW); //off

    11 Comments so far

    1. jim on November 19th, 2012

      I’m curious as to how one can use spwm and count on this chip, since these commands are not supported by the AT Tiny…? What are the limitations on which commands I can program? Can I make a random number generator to choose which led gets lit?

    2. admin on November 19th, 2012

      “++” is a mathematical expression and “spwm()” is a function included in the code, so both these things will run on the ATtiny chips. i don’t think the “random()” function will work though. for a full list of the supported Arduino commands look at the bottom of this page:
      >> http://hlt.media.mit.edu/?p=1695

    3. jim on November 19th, 2012

      Thanks! I wonder then, is there another way to generate random numbers on the AT 45 or 85? I would like to scramble the order of the fading here, for example.

    4. admin on November 19th, 2012

      I feel like there may be a way more professional way, and not even sure if this would work, but you could try simply reading an analog value from one of the pins and doing some math with the number you read to result in one of the LEDs?

    5. jim on November 19th, 2012

      I’m having difficulty getting this code to compile. I get an error stray ‘\’, which as I understand means I have a unicode character in there, but I see nothing strange. I have copied your code exactly and pasted, but it won’t compile. Is it me? I tried Ernie’s original code and it runs, but I really like your version better for effect! 🙂

    6. admin on November 19th, 2012

      here is a link to the code version of the sketch:
      >> https://github.com/plusea/CODE/blob/master/WORKSHOP CODE/SOFTandTINY/a_softPWMfade5/a_softPWMfade5.ino

    7. smching on December 6th, 2012

      your a_softPWMfade5.ino download link is broken, it should be
      https://github.com/plusea/CODE/blob/master/WORKSHOP CODE/SOFTandTINY/a_softPWMfade5/a_softPWMfade5.ino

      Anyway, can you show me your sketch which is same as your video demo?

    8. smching on December 6th, 2012

      Very funny. I had corrected your download link. But it come back to the broken link again after click on Submit Comment button.

    9. smching on December 6th, 2012

      Him Jim:
      Erase this line ==> for(int fade=254;fade>1;fade–) { //fade off
      and key in manually. add a – behind fade- too.

    10. admin on December 7th, 2012

      thanks for all your comments smching! i don’t know what to do about the broken link, just recommend that people copy paste the whole link, rather than click on it. and thanks for fixing the error that comes from copy pasting the code!

    11. Tom on February 2nd, 2013

      // Pimped Ernst’s code, I did it on an 2313 (1 Mhz)

      // code (PIN’s) for ATtiny 2313
      // fades LEDs on all five pins on and off using software PW

      // ATMEL ATTINY2313
      // -\/-
      // PA2 1| |29 VCC
      // RX (D 0) PD0 2| |19 PB7 (D 16)
      // TX (D 1) PD1 3| |18 PB6 (D 15)
      // (D 2) PA1 4| |17 PB5 (D 14) R=330 Ohm LED
      // (D 3) PA0 5| |16 PB4 (D 13) —||||———Red—–|
      // INT0 (D 4) PD2 6| |15 PB3 (D 12) —||||——–Yellow—|
      // INT1 (D 5) PD3 7| |14 PB2 (D 11) —||||——–Green—-|
      // (D 6) PD4 8| |13 PB1 (D 10) —||||——– Red—–|
      // *(D 7) PD5 9| |12 PB0 (D 9) —||||——–Yellow—|
      // GND 10| |11 PD6 (D 8)
      // —-
      // * indicates PWM port

      #define fadeSpeed 1
      int fade=0;

      void setup()
      for(int pin=9;pin<14;pin )
      pinMode(pin, OUTPUT);
      void loop(){
      for(int pin=9;pin<14;pin )
      softPWM(pin, fade, fadeSpeed);
      for(int pin=12;pin>9;–pin)
      softPWM(pin, fade, fadeSpeed);

      void softPWM(int pin, int freq, int sp)
      digitalWrite(pin,HIGH); //on
      digitalWrite(pin,LOW); //off

    Leave a comment