@ Override public void setValue ( Pin pin , double value ) { // validate range if ( value <= getMinSupportedValue ( ) ) { value = getMinSupportedValue ( ) ; } else if ( value >= getMaxSupportedValue ( ) ) { value = getMaxSupportedValue ( ) ; } // the DAC only supports integer values between 0..4095 int write_value = ( int ) value ; try { // create data packet and seed targeted value byte packet [ ] = new byte [ 3 ] ; packet [ 0 ] = ( byte ) MCP4725_REG_WRITEDAC ; packet [ 1 ] = ( byte ) ( write_value >> 4 ) ; // Upper data bits (D11.D10.D9.D8.D7.D6.D5.D4) packet [ 2 ] = ( byte ) ( write_value << 4 ) ; // Lower data bits (D3.D2.D1.D0.x.x.x.x) // write packet of data to the I2C bus device . write ( packet , 0 , 3 ) ; // update the pin cache and dispatch any events super . setValue ( pin , value ) ; } catch ( IOException e ) { throw new RuntimeException ( "Unable to write DAC output value." , e ) ; } }
Set the analog output value to an output pin on the DAC immediately .