//DAC: Single byte //A. J. Misquitta /* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * */ void setup(){ //set digital pins 0-7 as outputs for (int i=0;i<8;i++){ pinMode(i,OUTPUT); } pinMode(A0,INPUT); Serial.begin(9600); // Output to Serial while (! Serial); // Wait untilSerial is ready Serial.println("DAC: Single Byte!"); } void loop(){ digitalWrite(0, HIGH); // 1 : remember we start from the rightmost bit digitalWrite(1, LOW); // 0 digitalWrite(2, LOW); // 0 digitalWrite(3, LOW); // 0 digitalWrite(4, HIGH); // 1 digitalWrite(5, HIGH); // 1 digitalWrite(6, LOW); // 0 digitalWrite(7, HIGH); // 1 //delayMicroseconds(50);//wait 50us if using an oscilloscope //delay(100);//wait 100ms if using a multimeter/serial port /* Having written the byte to the digital pins, we will read the output of the DAC using the analogue pin A0 of the Arduino Uno. The analogue pins are Analogue to Digital converters (ADC). Read the DAC output into variable DACout and write it to the serial port. */ int DACout = analogRead(A0); if (Serial.available()) { Serial.println(DACout); } delay(100); }