Shop OBEX P1 Docs P2 Docs Learn Events
Please help with this question — Parallax Forums

Please help with this question

basicstampedebasicstampede Posts: 214
edited 2004-09-16 20:15 in General Discussion
import stamp.core.*;
···· public class ex2 {
······ final static int LEDpin = CPU.pin0;····· //int works, so does char, short, but not long
······ //final static int LEDpin = CPU.pins[noparse][[/noparse]0];·· // Error IDE-0042 Unknown unhandled exception in JVM [noparse][[/noparse]527]
······ public static void main() {
········ int ontime=10000;
········ int offtime = 5000;
·········while (true) {
·········· CPU.writePin (LEDpin, true);
·········· CPU.delay (ontime);
·········· CPU.writePin (LEDpin, false);
·········· CPU.delay (offtime);
········ }
······ }
··· }

Please help me understand why

final static int LEDpin = CPU.pins[noparse][[/noparse]0]; does not compile but
final static int LEDpin = CPU.pin0 does.

What is the difference between those two statements from Javelin's perspective????

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2004-09-15 18:51
    The problem is probably the final keyword.

    ·define· static int LEDpin = CPU.pins[noparse][[/noparse]0];··

    and you're probably ok.
    It can not be final as the pins[noparse]/noparse array does not exist in compile time.

    regards peter
    ·
  • basicstampedebasicstampede Posts: 214
    edited 2004-09-15 19:02
    No.· I tried

    static int LEDpin = CPU.pins[noparse][[/noparse]0];

    It compiles, and downloads, then resets, then gives an error message.

    Does anyone have a good explanation?
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2004-09-15 19:23
    From my other post,

    Alternatively, you may put the assignment at the beginning of your main()
    like
    static int LEDpin;
    static void main() {
    · LEDpin = CPU.pins[noparse][[/noparse]0];
    · //other code
    }
    because the moment main() is executed you know that all classes
    are initialized regarding globals.

    regards peter
  • basicstampedebasicstampede Posts: 214
    edited 2004-09-16 20:13
    No.· That doesn't work either.

    This is what I tried according to your advice.

    ·public static void main() {
    ········ static int LEDpin = CPU.pins[noparse][[/noparse]0];·· // Error IDE-0042 Unknown unhandled exception in JVM [noparse][[/noparse]527]
    ········ int ontime=10000;
    ········ int offtime = 5000;

    ········ etc....

    If I declare the LEDpin inside main, it does not even compile.



    Still a mystery.
  • basicstampedebasicstampede Posts: 214
    edited 2004-09-16 20:15
    Ooops.· That does work.·



    ·import stamp.core.*;

    ···· public class ex2 {

    ·······static int LEDpin;

    ······ public static void main() {
    ········ LEDpin = CPU.pins[noparse][[/noparse]0];
    ········ int ontime=10000;
    ········ int offtime = 5000;...etc.

    This now works.·



    Thanks.
Sign In or Register to comment.