Stap 3: Software
Zoals u in het codevoorbeeld hieronder, zien kunt omdat alle MCU en Interrupts intensieve decoratieve spullen (fasedetectie, Zerocrossing Detection, Sync, enz) zijn allemaal gedaan op de MPDMv4 universele AC Dimmer directieniveau, de Arduino software zijde is dodelijk simpel en zonder enige vorm van overhead door de dimmen verwerkingsfuncties toegevoegd:
/* Dimmer This simple Sketch demonstrates the sending data from the computer to the Arduino board, in this case to control the brightness of MPDMv4 AC MAINS Dimmer. The data is sent in individual bytes, each of which ranges from 0 to 255. Arduino reads these bytes and uses them to set the VCNT brightness command . The circuit: MPDMv4 Board attached from digital pin 3 to ground. Serial connection to Processing, Max/MSP, or another serial application created 2006 by David A. Mellis modified 30 Aug 2011 by Tom Igoe and Scott Fitzgerald modified 14 Apr 2016 by TJ for esp8266-projects.com AC MAINS Power Dimmer MPDMv4 Driver This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Dimmer */
const int vcntPin = 3; // the pin that the MPDMv4 VCNT pin is attached to
void setup() { // initialize the serial communication: Serial.begin(9600); // initialize the VCNTPin as an output: pinMode(vcntPin, OUTPUT); // set default brightness value analogWrite(vcntPin, 230); }
void loop() { byte brightness; // check if data has been sent from the computer: if (Serial.available()) { // read the most recent byte (which will be from 0 to 255): brightness = Serial.parseInt(); Serial.print("Command received : "); Serial.println(brightness); // set the brightness of the LED: analogWrite(vcntPin, brightness); } }