Controlling a PWM over I2C

Aus DL8RDS Wiki
Version vom 7. November 2009, 01:03 Uhr von Dl8rds (Diskussion | Beiträge) (New page: Pulse Width Modulation is a way to control the production of voltages. The hardware that is being used here is a BV4237: * http://www.byvac.com/bv/bv4237.htm The below given code sample ...)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

Pulse Width Modulation is a way to control the production of voltages. The hardware that is being used here is a BV4237:

The below given code sample is based on the code presented by the BB user wilkosoft:

#include <Wire.h>

#define dac 0x31

void sw16set(byte val) {
  Wire.beginTransmission(dac);  // join I2C, talk to BV4206 by id
  Wire.send(0x16);   //tell it what pin you want
  Wire.send(val);  //the state of the pin, from 0-8 (PWM controls the levels)
  Wire.endTransmission();      // leave I2C bus
  delay(100) ;
}

void setup()
{
  Wire.begin();
  Serial.begin(9600);
}

void loop()
{
  for (byte i=0; i<9; i++) {
    sw16set(i);
  }
}