Shop OBEX P1 Docs P2 Docs Learn Events
Passing a string value to a function - How? — Parallax Forums

Passing a string value to a function - How?

oakguyoakguy Posts: 21
edited 2014-01-03 11:06 in Learn with BlocklyProp
Guys
I am working with my activity bot and was building this and playing with using function calls for the first time. All my functions worked except when I realized I did not know how to instantiate a string variable in Propeller C. In my Void Display function I wanted to pass a string value as to where my servo was looking. I realize that I could do it an easier way. I was just trying to pass a string value. But I could not even create one. Functions sure do clean up your code.



void Display(string pointer,int cmDist)
{
print("pointer = %d, cmDist = %d\n", pointer, cmDist);
}

Thanks
Oakguy



#include "simpletools.h"
#include "servo.h"
#include "ping.h"
#include "wavplayer.h"
int main()
{


int delay1 = 1000;
int delay2 = 3000;
int cmDist = 0;
pointer = ("Forward");
//Opening Wave file and Ping forward
PlayWav();
servo_angle(17, 900);
pause(2000);

while(1)
{
servo_angle(17, 0);
pause(delay1);
cmDist = ping_cm(8);
Buzzer();
pointer = "Right";
Display(pointer, cmDist);
pause(delay2);


servo_angle(17, 900);
pause(delay1);
cmDist = ping_cm(8);
Buzzer();
pointer = "Forward";
Display(pointer, cmDist);
pause(delay2);


servo_angle(17, 1800);
pause(delay1);
cmDist = ping_cm(8);
Buzzer();
pointer = "Left";
Display(pointer, cmDist);
pause(delay2);


servo_angle(17, 900);
pause(delay1);
cmDist = ping_cm(8);
Buzzer();
pointer = "Forward";
Display(pointer, cmDist);
pause(delay2);
}
}


void Display(string pointer,int cmDist)
{
print("pointer = %d, cmDist = %d\n", pointer, cmDist);
}


void PlayWav(void)
{
int DO = 22, CLK = 23, DI = 24, CS = 25;
int Buzzer = 4, Duration = 250, Frequency = 4000;


//Mount the SD Card
sd_mount(DO, CLK, DI, CS);
const char techloop[] = {"techloop.wav"};
//play intro sound file
wav_play(techloop);
wav_volume(9);
pause(3500);
wav_stop();
}


void Buzzer(void)
{
int Buzzer = 4, Duration = 150, Frequency = 4000;
freqout(Buzzer, Duration, Frequency); //pin, duration, frequency
}

Comments

Sign In or Register to comment.