Sabtu, 10 Juni 2017

Menambah Pin PWM pada Arduino Dengan TLC5940

PWM merupakan fitur arduino yang sangat populer untuk mengendalikan led, namun arduino hanya memiliki sedikit pin yang dapat memproses PWM. Untuk itu kita dapat menambahnya dengan ic TLC5940 yang merupakan ic 16 channel PWM untuk driver led, motor, ataupun servo.



Fitur TLC5940:



  • VCC = 3 - 5 v
  • 16 channel
  • 12 bit (4096 Steps) PWM Control
  • Driving Capability 
             – 0 mA to 120 mA (VCC > 3.6V)
             – 0 mA to 60 mA (VCC < 3.6V)
  • Serial Data Interface
  • 30 MHz Data Transfer Rate
Rangkaian Arduino dan TLC5940





Library
Download disini


Sourcecode


/*
 * Arduino and TLC5940 Tutorial - Simple Example
 * by Dejan Nedelkovski, www.HowToMechatronics.com
 */
#include "Tlc5940.h" 
void setup() {
  Tlc.init(0); // Initiates the TLC5940 and set all channels off
}
 
void loop() {
  Tlc.set(0,4095); //(Output Pin from 0 to 15,PWM Value from 0 to 4095)
  // Note: The previous function doesn't activates the output right away. The output will be activated when the Tlc.update() function will be executed!
  
  Tlc.update(); // Activates the previously set outputs
  delay(1000);
  // For activating all 16 outputs at the same time we can use a for loop for setting all of them to be set to PWM value of 4095. Then  the Tlc.updata() function will active them all at the same time.
  for (int i = 0; i < 16; i++) {
    Tlc.set(i, 4095);
  }
  Tlc.update();
  delay(1000);
  //The Tlc.clear() function clears all the outputs, or sets the PWM value of all outputs to 0
  Tlc.clear();
  Tlc.update();
  delay(1000);
  // This for loop will active all 16 LEDs one by one
  for (int i = 0; i < 16; i++) {
    Tlc.set(i, 4095);
    Tlc.update();
    delay(200);
    Tlc.clear();
    Tlc.update();
    delay(200);
  }
}

1 komentar: