Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

bool status after going true then false

boolstate reboot

  • Please log in to reply
7 replies to this topic

#1 Bradski

Bradski

    Member

  • Members
  • PipPip
  • 14 posts
  • LocationUSA

Posted 17 July 2013 - 04:14 AM

Anyone have an example to solve a bool changing with a true then false and not just a true true true.

 

see code.

 

if (watchdogTimer < 200)
                {
                 
                    leftDrive.SetDutyCycle((uint)rxData[0]);
                    rightDrive.SetDutyCycle((uint)rxData[2]);
                    status = lights.Read();
 
                    if (rxData[3] == (int)1) // getting 1-6 1s in a row at random  need to change only after not being int 1.  bool the status. 
                       
                    lights.Write(!status);
                    if (rxData[10] == (int)01)
                        Debug.Print("10");
                    if (rxData[10] == (int)02)
                        reboot(true);


#2 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 17 July 2013 - 09:01 AM

Not to sure what you mean to be honest.

 

Do you mean a toggle function i.e. if true then set false, if false then set true?

//Very simple togglevar toggleBool = false; //Define boolwhile(true){  toggleBool = !toggleBool;  lights.Write(toggleBool);  Thread.Sleep(1000);}

or as your comment alludes to do you want to toggle the bool if you receive a number that isnt "1"?

//Toggle on condition//Very simple togglevar toggleBool = false; //Define boolvar counter = 0;while(true){  if(counter%3==0){//If the counter is a factorial of 3 toggle the bool    toggleBool = !toggleBool;  }  lights.Write(toggleBool);  Thread.Sleep(1000);  counter++;}

The example above will toggle the bool when the counter contains a number divisible by 3, i.e. 0,3,6,9,12...

 

Hope that helps

 

Nak.



#3 Bradski

Bradski

    Member

  • Members
  • PipPip
  • 14 posts
  • LocationUSA

Posted 18 July 2013 - 01:48 AM

Thanks for the code examples.  The problem I have is the lights are turning on and off with every 1 it gets every 100ms when a button is being pushed on a gamepad controller from another program.  So sometimes the lights will stop at true, sometimes at false depends on the quickness of your finger presses on the button.  Then maybe I could only change the lights being on or off by the rxdata int 1 (button pressed for longer than 100ms) then rxdata not int 1 or 0 (button not pressed). Like a set of true then false changes  the lights status not just true true true(1 ,1 )

(1,1,1,1,0) change status once and not four times

(1,1,1,1,1,1) button press turns lights on and off 6 times in 600ms. (big problem)

but I need the speed for joystick control so no thread.sleep allowed.



#4 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 18 July 2013 - 10:21 AM

Ok, so am i right in saying that you want the led to illuminate if you receive a 1 and to be extinguished if you receive any other number?

 

If you dont impose some sort of delay between the turning the led on and off it will look like its either never on or never off as its flashing to fast for you to see.  What is stopping you from controlling the led from annother thread if you dont want to use thread.sleep in your main code?

 

Nak.



#5 Bradski

Bradski

    Member

  • Members
  • PipPip
  • 14 posts
  • LocationUSA

Posted 18 July 2013 - 11:11 PM

Ok, so am i right in saying that you want the led to illuminate if you receive a 1 and to be extinguished if you receive any other number?

 

If you dont impose some sort of delay between the turning the led on and off it will look like its either never on or never off as its flashing to fast for you to see.  What is stopping you from controlling the led from annother thread if you dont want to use thread.sleep in your main code?

 

Nak.

Not Really the led needs to light after receiving a  1 or a string of 1's and not 1 or any other number in my case 0.

and go off after receiving a  1 or a string of 1's and not 1 or any other number in my case 0.

it receives 0 every 100ms when no button is pressed and a 1 every 100ms when the button is pressed.

1 and 0 turns on

1 and 0 turns off

1 and 1 nothing happen

0 and 0  nothing happen.

 

Brad



#6 Bradski

Bradski

    Member

  • Members
  • PipPip
  • 14 posts
  • LocationUSA

Posted 19 July 2013 - 01:16 AM

Heres the other end gets refreshed every 100ms.

 

maybe make some changes here?

 

public void controlla()
        {
 
            double lt2 = (controls.LeftStick.Position.Y * 101);
            lt1 = (int)lt2;
            double rt2 = (controls.RightStick.Position.Y * 101);
            rt1 = (int)rt2;
            double ud2 = (controls.LeftStick.Position.X * 101);
            udf1 = (int)ud2;
            if (controls.X) l1 = 1;    // lights on off commander!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            else l1 = 0;
         
            if (controls.B) i1 = 1;
            else i1 = 0;
 
            udr = 0;
            v1 = 0;
            wt1 = 0;
            st1 = 0;
            dpt1 = 0;
            if (startbutton) commun = 1;
 
            if (controls.Back) commun = 2;
            else commun = 0;
            if (rebootbutton) commun = 2;
                     
            Console.Write(commun);
         
            if (rebootbutton) rebootbutton = false;
            byte leftthrust = (byte)(lt1);
            byte rightthrust = (byte)(rt1);
            byte updownfront = (byte)(udf1);
            byte lights = (byte)(l1);
            byte Infared = (byte)(i1);
            byte updownrear = (byte)(udr);
            byte voltage = (byte)(v1);
            byte watertemp = (byte)(wt1);
            byte subtemp = (byte)(st1);
            byte depth = (byte)(dpt1);
            byte communication = (byte)(commun);
 
            byte[] maindata = { leftthrust, rightthrust, updownfront, lights, Infared, updownrear, voltage, watertemp, subtemp, depth, communication };
 
            Byte[] sendBytes = maindata;
            try
            {


#7 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 19 July 2013 - 08:46 AM

Hi Brad

 

Could you post you code using the code insert tool (<> in the toolbar in the message editor), much easier to read then :), also looks like the code you posted has been truncated as i cant see anything which relates to led's or data received...

 

Nak.



#8 Bradski

Bradski

    Member

  • Members
  • PipPip
  • 14 posts
  • LocationUSA

Posted 19 July 2013 - 02:39 PM

Thats because its on a windows form application not on the netduino.  Where all the data is coming from.

the lights commander is the part that controls the light on the netdunio via ethernet using  a udp socket.







Also tagged with one or more of these keywords: boolstate, reboot

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.