none
C# question RRS feed

  • Question

  • Hi,

    please i have one Programm( code)  im Arduino( Pusbutton on) , but i need to convate  this Programm in C#.

    please can you Help me? How can i write this code in C#.

    Code for Test  Teensys 3.2  Arduino.

    Void setup () {

    • pinMode(0, INPUT_PULLUP);
    • pinMode(1, INPUT_PULLUP);
    • }

     

    • void loop() {
    • // read analog inputs and set X-Y position
    • //Joystick.X(analogRead(0));
    • //Joystick.Y(analogRead(1));

     

    • // read the digital inputs and set the buttons
    • Joystick.button(1, digitalRead(0));
    • Joystick.button(2, digitalRead(1));

     

    • // a brief delay, so this runs 20 times per second
    • delay(50);}

     

     

    Wednesday, August 9, 2017 11:58 AM

All replies

  • please i have one Programm( code)  im Arduino( Pusbutton on) , but i need to convate  this Programm in C#.

    please can you Help me? How can i write this code in C#.

    Code for Test  Teensys 3.2  Arduino.

    Void setup () {

    • pinMode(0, INPUT_PULLUP);
    • pinMode(1, INPUT_PULLUP);
    • }

     

    • void loop() {
    • // read analog inputs and set X-Y position
    • //Joystick.X(analogRead(0));
    • //Joystick.Y(analogRead(1));

     

    • // read the digital inputs and set the buttons
    • Joystick.button(1, digitalRead(0));
    • Joystick.button(2, digitalRead(1));

     

    • // a brief delay, so this runs 20 times per second
    • delay(50);}

     

    Wednesday, August 9, 2017 1:58 PM
  • What are you trying to do? You want to control an Arduino with C#? You would need to create you application in c# to send the commands you want your Arduino to execute.. 

    I played around with a small app to merely send a few simple commands to my Arduino, and it worked, but thats as far as i got, since i was trying to do wifi communication.

    If you want to control the adruino from an app, you will need to update your arduino sketch to accept parameters, and listen on the serial port, then your c# app can send data over that serial/com port and let the arduino react to the received data.

    Wednesday, August 9, 2017 9:18 PM
  • Hi Frage,

    According to your question is more related to Arduino, you could post a new  thread to Arduino forum  for suitable support.

    The Visual C# discuss and ask the C# programming language, IDE, libraries, samples and tools.If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Best Regards,
    Feih-7


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, August 10, 2017 6:20 AM
  • This is insufficient code to convert to C# or any program really. .NET doesn't directly support joysticks so you need to decide what game library you'd want to use and then post your question in their forums. DirectX is the closest thing MS has so if you want an MS solution then please post your question in their forum.
    Thursday, August 10, 2017 6:29 PM
  • Hallo,

    thks for your answer. I want to realise a small project in c#. i  already have to do it with Arduino, now i need to realise the same Programm in c#. With a Tennsy 3.2 have realised it in Arduino. 

    when you push one Button for circuit  , you see in Gamecontroller  which button  you have pushed, for Example button 1 give 1.

    I need your solution, how can i do the same Things in Visual Studio C#.

    Best Regards.

    Lepro
    Tuesday, August 15, 2017 7:59 AM
  • void setup() {
      //serial.begin(9600);
      pinMode(0, INPUT_PULLUP);
      pinMode(1, INPUT_PULLUP);
      pinMode(2, INPUT_PULLUP);
      pinMode(3, INPUT_PULLUP);
      pinMode(4, INPUT_PULLUP);
      pinMode(5, INPUT_PULLUP);
      
    }
    
    void loop() {
      // read analog inputs and set X-Y position
    //  Joystick.X(analogRead(0));
    //  Joystick.Y(analogRead(1));
    
      // read the digital inputs and set the buttons
    //  if(serial.available())
    //  {
      Joystick.button(1, digitalRead(0));
      Joystick.button(2, digitalRead(1));
      Joystick.button(3, digitalRead(2));
      Joystick.button(4, digitalRead(3));
      Joystick.button(5, digitalRead(4));
      Joystick.button(6, digitalRead(5));
      
    
    
      // a brief delay, so this runs 20 times per second
      delay(50);
    }

    Tuesday, August 15, 2017 8:00 AM
  • thks for your answer. I want to realise a small project in c#. i  already have to do it with Arduino, now i need to realise the same Programm in c#. With a Tennsy 3.2 have realised it in Arduino. 

    when you push one Button for circuit  , you see in Gamecontroller  which button  you have pushed, for Example button 1 give 1.

    I need your solution, how can i do the same Things in Visual Studio C#.

    Best Regards.

    Lepro
    void setup() {
      //serial.begin(9600);
      pinMode(0, INPUT_PULLUP);
      pinMode(1, INPUT_PULLUP);
      pinMode(2, INPUT_PULLUP);
      pinMode(3, INPUT_PULLUP);
      pinMode(4, INPUT_PULLUP);
      pinMode(5, INPUT_PULLUP);
      
    }
    
    void loop() {
      // read analog inputs and set X-Y position
    //  Joystick.X(analogRead(0));
    //  Joystick.Y(analogRead(1));
    
      // read the digital inputs and set the buttons
    //  if(serial.available())
    //  {
      Joystick.button(1, digitalRead(0));
      Joystick.button(2, digitalRead(1));
      Joystick.button(3, digitalRead(2));
      Joystick.button(4, digitalRead(3));
      Joystick.button(5, digitalRead(4));
      Joystick.button(6, digitalRead(5));
      
    
    
      // a brief delay, so this runs 20 times per second
      delay(50);
    }

    Tuesday, August 15, 2017 8:02 AM
  • Again, this isn't going to work in C# directly. You need to pick a UI framework. C# is UI agnostic so there are no buttons or anything. The UI framework (Winforms, UWP, DirectX, WPF, etc) will provide this infrastructure. Pick your UI framework and then post the question in their forums and they can help you out. For a starter UI I'd probably go with Winforms myself.
    Tuesday, August 15, 2017 1:33 PM