Pages: [1]   Go Down
Author Topic: Arduino Due DAC Tutorial Problem  (Read 836 times)
0 Members and 1 Guest are viewing this topic.
USA
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I'm trying to run a tutorial I found on the arduino site, here, using the due:

http://arduino.cc/en/Tutorial/DueSimpleWaveformGenerator

The compiler returns an error with the example code:  't_sample' was not declared in this scope

My frustration is that the variable declared directly above it seems to work just fine. What's the problem here? Is the compiler broken?

Here's the beginning of the program listed on the tutorial:

#include "Waveforms.h"

#define oneHzSample 1000000/maxSamplesNum  // sample for the 1Hz signal expressed in microseconds

const int button0 = 2, button1 = 3;
volatile int wave0 = 0, wave1 = 0;

int i = 0;
int sample;

void setup()
{
  analogWriteResolution(12);  // set the analog output resolution to 12 bit (4096 levels)
  analogReadResolution(12);   // set the analog input resolution to 12 bit

  attachInterrupt(button0, wave0Select, RISING);  // Interrupt attached to the button connected to pin 2
  attachInterrupt(button1, wave1Select, RISING);  // Interrupt attached to the button connected to pin 3
  
  sample = 0;
}

void loop()
{
  // Read the the potentiometer and map the value  between the maximum and the minimum sample available
  // 1 Hz is the minimum freq for the complete wave
  // 170 Hz is the maximum freq for the complete wave. Measured considering the loop and the analogRead() time
  sample = map(analogRead(A0), 0, 4095, 0, oneHzSample);
  sample = constrain(t_sample, 0, oneHzSample);

  analogWrite(DAC0, waveformsTable[wave0]);  // write the selected waveform on DAC0
  analogWrite(DAC1, waveformsTable[wave1]);  // write the selected waveform on DAC1
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46029
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just remove the t_ from the name. It is the value from the previous line that is (supposed) to be constrained.
Logged

USA
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Can't believe I missed that. Thanks.
Logged

Dubai, UAE
Offline Offline
Edison Member
*
Karma: 21
Posts: 1670
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you like the sounds that makes, here is a very similar but slightly more complex approach that make a far more entertaining set of sounds. Justvbe very careful what you connect your DAC output to, a few of us have burned them out.

http://rcarduino.blogspot.ae/2012/11/quick-and-dirty-synth-for-arduino-due.html

Duane B

rcarduino.blogspot.com

Logged


Pages: [1]   Go Up
Jump to: