login

online now

We have 58 guests and no members online

search

 
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC: Severely challenged user

Severely challenged user 4 years 8 months ago #328

I have read every word and nuance of the Ginsing reference, but sadly, I might as well be reading Swahili in a mirror. Pointers, static classes, subclass interfaces and accessors... I've found that I cannot formulate adequate representation in my mind to make sense out of the jargon. The terms just seem disembodied and I'm unable to piece together an overall cognitive view of the sum of all parts in order to know where and how the constituents fit together.

I know. Personal problem for sure. But it's exquisitely frustrating. I must be simply a dull boy.

Most if not all of your examples show code being run in the setup() section of the sketch. I see that you're running a for() loop in there. It seems a little strange to me to see looping code in the setup section. How can I run it in the loop() section? I've tried just about everything I could feebly think of, but I can't add or subtract or move one character of code without rendering the example un-runnable. And all I'm trying to do is fool around with Preset mode. For example:

for ( int presetIdx = (int) SpaceWarp; presetIdx < (int) AmpMod; presetIdx++ )


How are these variables presenting integers to the following recursion:

preset->load ( 0 , (GSPreset) presetIdx );

(Or are integers necessary?)

And what is "AmpMod" doing? That variable is found no where else in the example. And how are you able to step through the presets one by one simply by using SpaceWarp? and I can't figure out what the < is doing. For that matter, the entire example is largely an enigma to me.

I'd really like to know how I could trigger and modulate the presets using external stimulus (Either binary or continuous or both) e.g., switches and/or sensors.

I don't know what I'm really asking for here, other than hoping someone can explain a few of these things to me in a way that they'll click....

Thanks.
Last Edit: 4 years 7 months ago by administrator.
The administrator has disabled public write access.

Re: Severely challenged user 4 years 8 months ago #329

Sorry to hear that you are having trouble. Hopefully we can get you up and running quickly. The manuals can be intimidating to the user because they do cover c++ topics without an introduction.

The sample programs run a for loop in the main program just to keep the code together (and allow the program to actually stop), but you can certainly remove the for loop and move the code into the loop() section. Keep in mind any variables you declare will need to be seen by both the setup() and loop() functions. Here, for example, is the presetmode sample program broken into the two functions:
int presetIdx = (int) SpaceWarp;

void setup ()
{
  
  GS.begin ( rcvPin , sndPin , ovfPin );
  
  GinSingPreset * preset = GS.getPreset();
  preset->begin (); 
}

void loop ()
{
  presetIdx++;
  if ( presetIdx > (int) AmpMod ) presetIdx = (int) SpaceWarp;

    preset->load    ( 0 , (GSPreset) presetIdx ); 
    preset->trigger ( 0 );
    
    delay ( 1000 ); 
    
    preset->release ( 0 );
    

}

A bit of explanation about the argument to preset->load() is in order here. In the c language, you can create a list of very specific values under a common name; this is referred to as an enumeration. The idea here is that if you have a function ( i.e. preset->load() ), it might be possible to call it with a bad value if you don't know what values are proper for the function. In the GinSingDefs.h file, you can see this enumeration spelled out:
enum GSPreset
{
	SpaceWarp    = 0  ,	Waba       =  1 ,	RandomThoughts =  2 ,	Gong         = 3 ,	Pwang        =  4 ,	Wow         =  5 ,
	Rananana     = 6  ,	Twarty     =  7 ,	Telly          =  8 ,	Pulsator     = 9 ,	Bound        = 10 ,	TipToe      = 11 ,
	Spokes       = 12 ,	Chopper    = 13 ,	Phazer         = 14 ,	PowerLines   = 15,	HeavyMetal1  = 16 ,	HeavyMetal2 = 17 ,
	ACMotor      = 18 ,	YaYa       = 19 ,	March          = 20 ,	NoiseChatter = 21,	BlipChatter  = 22 ,	Carney      = 23 ,
	EarthQuake   = 24 ,	MindProbe  = 25 ,	Siren          = 26 ,	Squaba       = 27,	SteamLoco    = 28 , FreqMod     = 29 , 
	AmpMod       = 30
};

So basically this bit of code in the GinSingDefs.h header file defines all the possible valid inputs that a function using the GSPreset argument can accept. In this case, the values 0-30 are valid as they are the only ones defined. Furthermore, each of these values has its own specific name associated with the value. In the "normal" condition, you would call the preset->load() function with one of the available options defined here, as in :
preset->load ( 0 , HeavyMetal1 );

All this really does is substitute the value (16) for the enumeration in the header file, but it also ensures that only the names in GSPreset can be used as valid arguments to this function. If you actually try to call this function with any general value you will find that it will not compile:
preset->load ( 0 , -1 );   // this will generate a compiler error

This would produce unexpected results if it did compile since the function does not allow you to use a general integer as an argument - it must be a GSPreset as an argument. Hopefully this makes some sense, but basically the language allows you the ability to restrict the arguments that can be used for the function.

Now, in the sample program, we are using a test integer ( presetIdx ) that we want to increment each time through the loop rather than explicitly using one of the enumerations the function expects. Because of this, we are tricking the function by casting it into the GSPreset enumeration when we call the function. Likewise, when we check the integer we cast the enumeration into an integer for the comparison. This is just a way to bypass the strict argument checking mechanism for this test case. In most cases you would never need to do any of this casting - its only done in the sample program to iterate through the available options. This is probably a dirty trick to play on the unsuspecting victim such as yourself; sorry for generating the confusion.

Given the enumeration declaration above, it you might observe that the "SpaceWarp" and "AmpMod" appearances in the code are simply constants that represent the first and last valid values of the argument to preset->load(). All the code is doing is making sure that our integer keeps within the range between the valid beginning and ending values.

I'm not sure if this has helped at all, but I am more than happy to go into more detail on this or other stuff that might be confusing. I appreciate your posting to the forum, and please feel free to use it for any question before getting too frustrated.
Last Edit: 4 years 8 months ago by administrator.
The administrator has disabled public write access.
  • Page:
  • 1
Time to create page: 0.172 seconds