Commit 251800be by karrku

Add new file

parents
Showing with 53 additions and 0 deletions
#include <SPI.h>
const int PIN_CS = 10;
const int GAIN_1 = 0x1;
const int GAIN_2 = 0x0;
void setup()
{
Serial.begin(300);
pinMode(PIN_CS, OUTPUT);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV2);
}
//assuming single channel, gain=2
void setOutput(unsigned int val)
{
byte lowByte = val & 0xff;
byte highByte = ((val >> 8) & 0xff) | 0x10;
PORTB &= 0xfb;
SPI.transfer(highByte);
SPI.transfer(lowByte);
PORTB |= 0x4;
}
void setOutput(byte channel, byte gain, byte shutdown, unsigned int val)
{
byte lowByte = val & 0xff;
byte highByte = ((val >> 8) & 0xff) | channel << 7 | gain << 5 | shutdown << 4;
PORTB &= 0xfb;
SPI.transfer(highByte);
SPI.transfer(lowByte);
PORTB |= 0x4;
}
void loop()
{
//high-res sine wave
for (int i=0; i < 256; i+=1)
{
//setOutput(0, GAIN_2, 1, i);
double a = (((double)i*(22/7))/127.5);
double b = ((sin(a)*0.5)+0.5)*255;
setOutput((int)b);
//Serial.println((int)b);
Serial.println(analogRead(A0));
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment