diff examples/03-Analog/scope-analog/render.cpp @ 542:3016638b4da2 prerelease

Analog examples updated
author Robert Jack <robert.h.jack@gmail.com>
date Fri, 24 Jun 2016 13:00:31 +0100
parents 1cec96845a23
children
line wrap: on
line diff
--- a/examples/03-Analog/scope-analog/render.cpp	Fri Jun 24 02:29:05 2016 +0100
+++ b/examples/03-Analog/scope-analog/render.cpp	Fri Jun 24 13:00:31 2016 +0100
@@ -37,6 +37,19 @@
     // setup the scope with 3 channels at the audio sample rate
 	scope.setup(3, context->audioSampleRate);
 	
+	// Check if analog channels are enabled
+	if(context->analogFrames == 0 || context->analogFrames > context->audioFrames) {
+		rt_printf("Error: this example needs analog enabled, with 4 or 8 channels\n");
+		return false;
+	}
+
+	// Check that we have the same number of inputs and outputs.
+	if(context->audioInChannels != context->audioOutChannels ||
+			context->analogInChannels != context-> analogOutChannels){
+		printf("Error: for this project, you need the same number of input and output channels.\n");
+		return false;
+	}
+	
 	gInverseSampleRate = 1.0 / context->audioSampleRate;
 	gPhase = 0.0;
 
@@ -66,8 +79,10 @@
 	    scope.log(out, in1, in2);
 	    
 	    // pass the sine wave to the audio outputs
-	    for(unsigned int channel = 0; channel < context->audioChannels; channel++)
-			context->audioOut[n * context->audioChannels + channel] = out;
+	    for(unsigned int channel = 0; channel < context->audioOutChannels; channel++) {
+	        audioWrite(context, n, channel, out);
+	    }
+			
 
 	}
 }
@@ -81,10 +96,10 @@
 /**
 \example scope-analog/render.cpp
 
-Connecting potentiometers
+Scoping sensor input
 -------------------------
 
-This example reads from analogue inputs 0 and 1 via `analogReadFrame()` and 
+This example reads from analogue inputs 0 and 1 via `analogRead()` and 
 generates a sine wave with amplitude and frequency determined by their values. 
 It's best to connect a 10K potentiometer to each of these analog inputs. Far 
 left and far right pins of the pot go to 3.3V and GND, the middle should be 
@@ -92,7 +107,21 @@
 
 The sine wave is then plotted on the oscilloscope. Click the Open Scope button to 
 view the results. As you turn the potentiometers you will see the amplitude and 
-frequency of the sine wave change.
+frequency of the sine wave change. You can also see the two sensor readings plotted
+on the oscilloscope.
+
+The scope is initialised in `setup()` where the number of channels and sampling rate
+are set.
+
+`````
+scope.setup(3, context->audioSampleRate);
+`````
+
+We can then pass signals to the scope in `render()` using:
+
+``````
+scope.log(out, in1, in2);
+``````
 
 This project also shows as example of `map()` which allows you to re-scale a number 
 from one range to another. Note that `map()` does not constrain your variable