zitronen

[Hardware, Plugin] Arduino based physical display + serial port io+ tutorial (10-06-17)

Recommended Posts

Uh... does it change if you change the refresh rate in the plug config file?

Share this post


Link to post
Share on other sites

Guys, what is the actual output of ControlStatus();

I'm trying to turn on LEDs using a TLC5940 chip, using:

Tlc.set(PIN, map(ControlStatus(LIGHTS),LOW, HIGH, 0, 2000));

to no avail. Also tried mapping from 0, 1. (note, the Tlc5940 uses a range from 0, 4096 for output values.)=

The example provided in the code is digitalWrite(SASLED,ControlStatus(AGSAS));

any idea how I can get this to map to my (0,4096) range?

 

A.J.

 

Edited by ajden

Share this post


Link to post
Share on other sites

Hey-O. Figured it out. It's actually:

Tlc.set(0, map(ControlStatus(AGLight),LOW, HIGH, 0, 2000));

These 5940 chips work pretty well if you want to control a bazillion LEDs from your Uno. 

A.J.

Share this post


Link to post
Share on other sites

Hi, Im playing around with controlling SAS modes, and I can't get them to work,
Just wanting to clarify that 

void controls(){
  if (connected){
       if (ButtonState){
           setSASMode(2);
       }
       KSPBoardSendData(details(CPacket));
  }
}

should engage prograde SAS? if not what am I doing wrong

Edit: 

KSP version and Pluggin are up to date, Windows 10
Im using a mega 

Edited by ohMorrissey

Share this post


Link to post
Share on other sites

You need to do it like the example code:

if (digitalRead(SASPIN)) { //--------- This is how you do main controls
      MainControls(SAS, HIGH);
      setSASMode(SMPrograde); //setting SAS mode
      //setNavballMode(NAVBallSURFACE); //setting navball mode
    }
    else {
      //setNavballMode(NAVBallTARGET);
      MainControls(SAS, LOW);
    }

MainControls(SAS, HIGH/LOW) does the actual turning on and off.

Since you are using win10, check using the example code to see if you are getting any control inputs at all.

Share this post


Link to post
Share on other sites
On 1/11/2018 at 1:08 PM, zitronen said:

You need to do it like the example code:


if (digitalRead(SASPIN)) { //--------- This is how you do main controls
      MainControls(SAS, HIGH);
      setSASMode(SMPrograde); //setting SAS mode
      //setNavballMode(NAVBallSURFACE); //setting navball mode
    }
    else {
      //setNavballMode(NAVBallTARGET);
      MainControls(SAS, LOW);
    }

MainControls(SAS, HIGH/LOW) does the actual turning on and off.

Since you are using win10, check using the example code to see if you are getting any control inputs at all.

I am trying to do the same thing, i think.

I have a master switch for SAS ON/OFF. But I want 10 buttons to change the state of SAS once it is on. I have tried putting just a separate if statement but that doesn't seem to help

Share this post


Link to post
Share on other sites
30 minutes ago, JoshTheCoward said:

I am trying to do the same thing, i think.

I have a master switch for SAS ON/OFF. But I want 10 buttons to change the state of SAS once it is on. I have tried putting just a separate if statement but that doesn't seem to help

Well don't you just want to set different SASModes then?  

Read the various control states in front of you, build the table of what you should do then code it.  I.e., if main sas switch is set, and then there's a multi-select dial set to a specific mode, read the mode switches, then choose what to do.  If you have different buttons for different modes, you'll have to read the master SAS state, and select it, perhaps toggling a hidden state variable in your MEGA about whether the next button push enables, or disables the master SAS mode.  You might use encoding of a bit-field and read the field from another "sub-controller" on your board.  And switching SAS modes with SAS disabled may make sense (like if you have a rotary switch control), or it may not make sense (if you just have buttons that may, or may not light up if the mode is chosen, and the mode is active).  I.e. push prograde twice (once to switch from target to prograde, then from prograde to off).  

As in any control system, it really does help to make a little table of what things should be first, otherwise debugging becomes a pain in the neck.  I use whiteboards (easy to erase) or pencil (easy to refer to my sheet of paper).  Without knowing exactly what you're up to I think you're just looking to set various nav ball modes based on the user's switches, but since we don't know exactly what switches you have, it's hard to guess at what's best for you.

  

Share this post


Link to post
Share on other sites
1 hour ago, morgeturd said:

Well don't you just want to set different SASModes then?  

Read the various control states in front of you, build the table of what you should do then code it.  I.e., if main sas switch is set, and then there's a multi-select dial set to a specific mode, read the mode switches, then choose what to do.  If you have different buttons for different modes, you'll have to read the master SAS state, and select it, perhaps toggling a hidden state variable in your MEGA about whether the next button push enables, or disables the master SAS mode.  You might use encoding of a bit-field and read the field from another "sub-controller" on your board.  And switching SAS modes with SAS disabled may make sense (like if you have a rotary switch control), or it may not make sense (if you just have buttons that may, or may not light up if the mode is chosen, and the mode is active).  I.e. push prograde twice (once to switch from target to prograde, then from prograde to off).  

As in any control system, it really does help to make a little table of what things should be first, otherwise debugging becomes a pain in the neck.  I use whiteboards (easy to erase) or pencil (easy to refer to my sheet of paper).  Without knowing exactly what you're up to I think you're just looking to set various nav ball modes based on the user's switches, but since we don't know exactly what switches you have, it's hard to guess at what's best for you.

  

How do I get it to change state with button push? 

if (digitalRead(SMSAS)) {
       setSASMode(SMSAS);
  }

This doesn't seem to work

 

I want it to work: 

 

If SAS switch is on then:

         if prograde button is pushed then switch to prograde ....

else 

 SAS is off

 

 

Here is my code:

void controls() {
  if (Connected) {

    if (digitalRead(SASPIN)) { 
      MainControls(SAS, HIGH);

     if (digitalRead(SMSAS)) {
       setSASMode(SMSAS);
     }
  
    if (digitalRead(SMPrograde)) {
      setSASMode(SMPrograde);
   
    }
   
   if (digitalRead(SMRetroGrade)) {
     setSASMode(SMRetroGrade);
    } 
   
    if (digitalRead(SMNormal)) {
       setSASMode(SMNormal);
    } 

    if (digitalRead(SMAntinormal)) {
       setSASMode(SMAntinormal);
    } 

     if (digitalRead(SMRadialIn)) {
       setSASMode(SMRadialIn);
    } 
    if (digitalRead(SMRadialOut)) {
       setSASMode(SMRadialOut);
    } 
     if (digitalRead(SMTarget)) {
       setSASMode(SMTarget);
    } 
    if (digitalRead(SMAntiTarget)) {
       setSASMode(SMAntiTarget);
    } 

     if (digitalRead(SMManeuverNode)) {
       setSASMode(SMManeuverNode);
    } 
        
 
    }
    else {
      
      MainControls(SAS, LOW);
    }
    


 

Edited by JoshTheCoward

Share this post


Link to post
Share on other sites
16 hours ago, JoshTheCoward said:

I am trying to do the same thing, i think.

I have a master switch for SAS ON/OFF. But I want 10 buttons to change the state of SAS once it is on. I have tried putting just a separate if statement but that doesn't seem to help

I got the modes working when I coded it so that the SAS is always on when the code is running, and the button changed direction (Pro/Retro) when (HIGH/LOW) and worked, 

the example code only activated SAS when the button was (HIGH), might be a Win10 bug? still working towards doing exactly what you are trying to do but i'm gonna construct my panels first.

PS: The example worked but mine didn't, found it only worked when I copied all my added code back into a fresh set of demo16 files. Couldn't find any difference between my old code and the copy back into the fresh files but it worked after none the less.

Share this post


Link to post
Share on other sites

JoshTheCoward,

Have you named your inputs the same as the SAS modes? I'm not sure you can get that to work since higher up in the code the SAS modes are defined. Example: "#define SMPrograde   2"  is up in the header of the main tab in the code. 

So maybe if your Prograde button is hooked up to pin #2, the following would work

   if (digitalRead(SMPrograde)) {
      setSASMode(SMPrograde);

But this isn't ideal, since you start running into serial I/O pins that should ideally be left blank (depending on your platform). 

 

Other "gotchas":

Make sure you declare the pinMode(WhateverPin, INPUT_PULLUP); somewhere

After some tribulations I discovered that my pushbuttons were NC instead of NO. That made the coding a bit more of a pain.

I'm fairly new to this, so if any of the above is way out in left field, please correct me for posterity's sake.

Share this post


Link to post
Share on other sites
On 1/13/2018 at 9:05 AM, ajden said:

JoshTheCoward,

Have you named your inputs the same as the SAS modes? I'm not sure you can get that to work since higher up in the code the SAS modes are defined. Example: "#define SMPrograde   2"  is up in the header of the main tab in the code. 

So maybe if your Prograde button is hooked up to pin #2, the following would work


   if (digitalRead(SMPrograde)) {
      setSASMode(SMPrograde);

But this isn't ideal, since you start running into serial I/O pins that should ideally be left blank (depending on your platform). 

 

Other "gotchas":

Make sure you declare the pinMode(WhateverPin, INPUT_PULLUP); somewhere

After some tribulations I discovered that my pushbuttons were NC instead of NO. That made the coding a bit more of a pain.

I'm fairly new to this, so if any of the above is way out in left field, please correct me for posterity's sake.

 

Ok so I rewrote it to 

 

That does not seem to work either. 

 

 

Update: I just re-assigned one of the buttons to my stage button and it worked no problem, do the physical button is working.

 

Update2: Never Mind I was using Serial inputs and it was messing it up.

Edited by JoshTheCoward

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now