Please help with this question
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????
···· 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
·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
·
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?
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
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.
·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.