Main Site Documentation

Cerberus Joystick issue


#1

Hello Guys,
im new to the .NET Gadgeteer and i have a probem with the Joysitck. I followed the instructions on the Tinyclr wiki about the Joystick.

My Code:

[quote]using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp4
{
public partial class Program
{
// This method is run when the mainboard is powered up or reset.
void ProgramStarted()
{
joystick.JoystickPressed += new Joystick.JoystickEventHandler(joystick_JoystickPressed);

        void joystick_JoystickPressed(Joystick sender, Joystick.JoystickState state)
    {
        do
        {
            led7r.Animate(350, true, true, false);
        } while (DateTime.Now >= DateTime.Today);
            Debug.Print("Program Started");
    }
        
        
        
    }
}

}
[/quote]

And i get two errors:
"expecting }"
and
"Type or namespace definition, or end-of-file expected"
Can someone help me

On the screenshot you can see the German version on C#, but the errors above are translated.

Benjamin


#2

You are missing closing curly bracket for ProgramStarted method


#3

And you have extra bracket at the end of the file.
Here is the proper format:


using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Gadgeteer.Modules.GHIElectronics;

namespace GadgeteerApp4
{
    public partial class Program
    {
        // This method is run when the mainboard is powered up or reset. 
        void ProgramStarted()
        {
            joystick.JoystickPressed += new Joystick.JoystickEventHandler(joystick_JoystickPressed);
            Debug.Print("Program Started");
        }

        void joystick_JoystickPressed(Joystick sender, Joystick.JoystickState state)
        {
            do
            {
                led7r.Animate(350, true, true, false);
            } while (DateTime.Now >= DateTime.Today);            
        }
    }
}



#4

@ Architect - Ah ok thank you


#5

You are welcome!


#6

Hello again,
I finally finished programming a light switch and wanted to try the XY positions of the joystick, but I have some problems.
I want to let the LED’s move to the direction the Joystick points to, but i have no clue where to start.
I already tried the tinyclr wiki, but i didnt understand what to do. (http://wiki.tinyclr.com/index.php?title=Joystick_Module#Polling_the_XY_Direction)

Could you give me a direction i could work on, if it isnt that much work?
That would be kind of awesome :wink:

Benjamin


#7

You just need to read Joystick position. Remember it. Then when you read next time you can find direction.


#8

Is it Possible to display the Variable “myposition” in CMD in real time ? ( i dont have a display on my Cerberus)


#9

Yes you can use Debug.Print and see what it prints in Output window in Visual Studio while debugging. You can also use MFDeploy to see the output.


#10

What is the Syntax for the debug.print i tried this:


#11

@ -Encore- - Support page has some good free e-books:
http://www.ghielectronics.com/support/dotnet-micro-framework

I recommend to start with the Beginners guide.


#12

Hi i have now programmed the led that i can switch them with the joystick, but i have a problem the LED’s 2 and 5 on the led7r are flickering weird.
Code:

void timer_Tick(GT.Timer timer)
        {
 
            double joystickPosX = joystick.GetJoystickPosition().X;
            double joystickPosY = joystick.GetJoystickPosition().Y;

            if (b == true)
            {
                if (joystickPosX > 0 && joystickPosX < 0.1 && joystickPosY > 0.4 && joystickPosY < 0.6)
                {
                    led7r.TurnLightOn(1, true);
                }

                else if (joystickPosX > 0 && joystickPosX < 0.499 && joystickPosY > 0.61 && joystickPosY < 0.997)
                {
                    led7r.TurnLightOn(2, true);
                }

                else if (joystickPosX > 0.51 && joystickPosX < 0.97 && joystickPosY > 0.76 && joystickPosY < 1)
                {
                    led7r.TurnLightOn(3, true);
                }

                else if (joystickPosX > 0.9 && joystickPosX < 1 && joystickPosY > 0.188 && joystickPosY < 1)
                {
                    led7r.TurnLightOn(4, true);
                }

                else if (joystickPosX > 0.501 && joystickPosX < 0.999 && joystickPosY > 0.001 && joystickPosY < 0.188)
                {
                    led7r.TurnLightOn(5, true);
                }

                else if (joystickPosX > 0 && joystickPosX < 0.49 && joystickPosY > 0 && joystickPosY < 0.399)
                {
                    led7r.TurnLightOn(6, true);
                }

                else
                {
                    led7r.TurnLightOff(1);
                    led7r.TurnLightOff(2);
                    led7r.TurnLightOff(3);
                    led7r.TurnLightOff(4);
                    led7r.TurnLightOff(5);
                    led7r.TurnLightOff(6);
                }
            }

My friend tried the same code and he gets the same problem on his led7r.
Do you guys have any solution ?


#13

Double Check your ranges. For example x 0.52 is true for two different cases in your code.


#14

Indeed your ranges aren’t correct. The following code should work correctly:


if (joystickPosX < 0.2 && joystickPosY > 0.4 && joystickPosY < 0.6)
{
    led7r.TurnLightOn(1, true);
}
else if (joystickPosX <= 0.4 && joystickPosY >= 0.6)
{
    led7r.TurnLightOn(2, true);
}
else if (joystickPosX >= 0.6 && joystickPosY >= 0.6)
{
    led7r.TurnLightOn(3, true);
}            
else if (joystickPosX > 0.8 && joystickPosY > 0.4 && joystickPosY < 0.6)
{
    led7r.TurnLightOn(4, true);
}                
else if (joystickPosX >= 0.6 && joystickPosY <= 0.4)
{
    led7r.TurnLightOn(5, true);
}
else if (joystickPosX <= 0.4 && joystickPosY <= 0.4)
{
    led7r.TurnLightOn(6, true);
}               
else
{
    led7r.TurnLightOff(1);
    led7r.TurnLightOff(2);
    led7r.TurnLightOff(3);
    led7r.TurnLightOff(4);
    led7r.TurnLightOff(5);
    led7r.TurnLightOff(6);
}           

@ -Encore-:
Many greetings from your teacher :slight_smile:

P.S.:
This week we’ll start with the programming of the gadgeteer robot. Because there are many people in the course who have no programming experience we’ll start the gadgeteer and robot programming with the programming language Scratch. Three weeks later we’ll use C# as our standard programming language.


#15

@ LarsO - Using Scratch to program Gadgeteer - interesting!


#16

We are a vocational school for technical education and for educational purposes each student constructs, builds and programs his own gadgeteer (Cerebrus) based robot to learn the basics of information technology, control engineering, electrical engineering, programming, etc. Especially for the introduction to programming the usage of Scratch has been proven. For this reason I have adapted the Scratch environment so that programming of the gadgeteer based robot is possible with Scratch. The adaption is based on Scratch (http://scratch.mit.edu) and especially on S4A (Scratch for Arduino, http://seaside.citilab.eu/scratch/arduino). Also an appropriate firmware for Cerberus was developed.


#17

Awesome! So how exactly Scratch works with Gadgeteer? Do you generate a C# code in background from the visual Scratch program?


#18

There’s no C# code in background from the visual scratch program. Scratch was completely written in the programming language Smalltalk, so my Gadgeteer Scratch version is a Smalltalk program, too. The communication between the visual Scratch program and the Gadgeteer system is via a serial interface (serial-usb module or bluetooth module).


#19

Ok, that explains it. Thanks!


#20

This is very interesting. Can you share more details? Maybe instructions on how we can use scratch with NETMF and gadgeteer?