51 const uint16_t DIVISOR = 1024 / 8;
54 uint8_t scaledValue, i;
69 pwOut <<
"Welcome to the MCP3000 demo!\n";
72 loopCounter = SECOND / 2 + CNT;
76 while (abs(loopCounter - CNT) > MILLISECOND) {
77 data = adc.
read(CHANNEL);
80 scaledValue = (uint8_t) ((data + DIVISOR / 2 - 1) / DIVISOR);
82 for (i = 0; i < scaledValue; ++i)
83 ledOutput = (ledOutput << 1) | 1;
84 scale.
write(ledOutput);
87 pwOut.
printf(
"Channel %d is reading: %d\n", CHANNEL, data);
The PropWare::SimplePort is the recommended way to use data ports on the Propeller. All pins are consecutive, which allows for some simple shortcuts in reading, writing, and initialization.
const PropWare::Port::Mask MISO
const PropWare::Port::Mask SCLK
void always_set_spi_mode(const bool alwaysSetMode)
Choose whether to always set the SPI mode and bitmode before reading or writing to the ADC; Useful wh...
MCP3004/MCP3008 ADC driver using SPI communication for the Parallax Propeller.
const PropWare::Printer pwOut
Most common use of printing in PropWare applications (not thread safe; see PropWare::pwSyncOut for mu...
void printf(const char fmt[], const T first, const Targs...remaining) const
Similar in functionality to the C-standard function printf.
const PropWare::MCP3000::PartNumber PART_NUMBER
uint16_t read(const MCP3000::Channel channel)
Read a specific channel's data in single-ended mode.
void write(uint32_t value) const
Allow easy writing to a port w/o destroying data elsewhere in the port; A shift is performed before w...
SPI serial communications library; Core functionality comes from a dedicated assembly cog...
const PropWare::Port::Mask MOSI
const PropWare::Port::Mask CS