krash wrote:rorschachuk wrote:Firstly, I doubt the two separate lines in Start to initialise output mode on GPC0 and GPC1 will work, I think you'd need to do both in one line as per my example, otherwise only the second one would work. Secondly, if you're checking two buttons, you shouldn't be switching OFF the pin you're not switching ON in the two if checks, because that'll stop you being able to press A and B together to switch on both simultaneously. As written, you'd be switching off both pins immediately after setting one or other (but not both) on.
- Code: Select all
#include "svt.h" //include Official API
#include "JAPI.h" //include "Secret sauce" API
#define GPC0 (1<<0) //bitmask for pin GPC0 = 00000001
#define GPC1 (1<<1) //bitmask for pin GPC1 = 00000010
#define GPC2 (1<<2) //bitmask for pin GPC2 = 00000100
#define GPC3 (1<<3) //bitmask for pin GPC3 = 00001000
#define GPC4 (1<<4) //bitmask for pin GPC4 = 00010000
#define GPC5 (1<<5) //bitmask for pin GPC5 = 00100000
#define GPC6 (1<<6) //bitmask for pin GPC6 = 01000000
#define GPC7 (1<<7) //bitmask for pin GPC7 = 10000000
int keystate; //define "keystate" as integer
void Start() {
//Set output mode for pins GPC0 and GPC1
JAPI_SetIoOutputMode(GPC0+GPC1);
}
bool Run() {
keystate=GetRemoteKeys(); //TRAKR remote control key pressed
//assign to keystate
if (keystate > 0) { //if keystate is greater than 0
if(keyState&KEY_INPUT1) { //Button A pressed (motor forward)
JAPI_SetIoHigh(GPC0); //Set GPC0 pin high (3.3v)
} else {
JAPI_SetIoLow(GPC0); //Switch off pin GPC0
}
if(keyState&KEY_INPUT2) { //Button B pressed (motor reverse)
JAPI_SetIoHigh(GPC1); //Set GPC1 pin high (3.3v)
} else {
JAPI_SetIoLow(GPC1); //Switch off pin GPC1
}
if(keystate & KEY_HOME) { //if Home button pressed
return false; //this will end the loop
}
}
return true; //loop will repeat until false
}
void End() { //Program end - switch off both pins
JAPI_SetIoLow(GPC0+GPC1);
}
Try this?
RorschachUK
"Secondly, if you're checking two buttons, you shouldn't be switching OFF the pin you're not switching ON in the two if checks, because that'll stop you being able to press A and B together to switch on both simultaneously."
If you are connecting the motor directly to the pins, if both pins go high, I think this would result in "braking" the motor (stopping it not ruining it). This is fine. However if you connect to an H-bridge circuit or IC, if both pins go high at the same time, this may burn out the circuit or IC.
Is there another way to ensure that both pins will not go high at the same time (A and B pressed at the same time and frying the circuit) yet ensure that the motor will remain in forward motion as long as button A is pressed yet stop when released? OR the motor will remain in reverse motion as long as button B is pressed yet stop when released?
When I compile this, it doesn't work. It comes up with error 9. Whatever that is. I'm trying to put a BB gun on my TRAKR, but I need this code snippet, or a code snippet, that will serve as a switch with GPC0 and GPC1 as a switch for a tesla coil. I need an app that will allow this when a button is pushed:

do you think you could post an app for this and send me the link to it, then tell me how to wire it?