Help learning Arduino programming from Basic Stamp2

I have been using the basic stamp for some time because it seemed to be the easiest programming to learn. I am trying to learn Arduino programming a it still is a challenge. In the programming I did with the basic stamp I used a lot of goto statements . Can some of you smart people help me and concert this simple basic stamp2 code to Arduino . Then it will help me understand a little more how it works.
Thanks,
BOB

' {$STAMP BS2}
' {$PBASIC 2.5}

#SELECT $STAMP
#CASE BS2, BS2E, BS2PE
T9600 CON 84
#CASE BS2SX, BS2P
T9600 CON 240
#ENDSELECT

GOTO Remolt:

Remolt:
DEBUG ? IN0
IF (IN0 =1) THEN ButtonA:
PAUSE 25
GOTO Remolt:
ButtonA:
PAUSE 500 ' Short delay
HIGH 4
PAUSE 200
GOTO Remolt:

It would help if you explained what the statements do as not everybody is familiar with the stamp.

For RemoIt, use the loop(). If DEBUG refers to reading serial input, use Serial.available() and Serial.read().

To setup the serial port, use Serial.begin().

Your if/goto will be an if/else.

HIGH 4 is probably an instruction to set pin 4high; in that case you can use digitalWrite(). And PAUSE will now be delay().

Look the above up in the reference, write and test and if you’re stuck, post the code. Indicate what it’s supposed to do and what it actually does.

And please use code tags when posting; see the ‘how to use this forum’ sticky about posting code.

There is a multitude of tutorials for arduino. My basic understanding of Arduino programming comes from Massimo Banzis Getting started with Arduino, Jeremy Blums youtube tutorial, Tronixstuff and of course this forum.

If you look at Jeremys lesson 1 I think you can convert half of that program into Arduino, and with lesson 2 more or less everything.

Here you go; this is a pretty direct translation.
Your original has a bug; after IN0 is 1 and you do "HIGH 4", nothing ever changes pin4 back to any NOT HIGH state.

#define IN0 5    // replace 5 with the pin number for input.

void setup() {
  Serial.begin(9600);   // T9600       CON     84  (setup debug connection ?)
  pinMode(4, OUTPUT);   // initialization
  digitalWrite(4, LOW); // ... start the output pin at low
  pinMode(IN0, INPUT);
}

void loop() {
  Serial.print(digitalRead(IN0));    // DEBUG ? IN0
  if (digitalRead(IN0) == HIGH) {    //  IF (IN0 =1) THEN ButtonA:
    delay(500);                      // ButtonA: PAUSE 500
    digitalWrite(4, HIGH);           // HIGH 4
    delay(200);
  } else {
    // IN0 is NOT 1.
    delay(25);                       // PAUSE 25
  }
}

ButtonA could be its own function. It might increase similarity with original code.
Double slash // is comments

#define IN0 5    // replace 5 with the pin number for input.

void setup() {
  Serial.begin(9600);   // T9600       CON     84  (setup debug connection ?)
  pinMode(4, OUTPUT);   // initialization
  digitalWrite(4, LOW); // ... start the output pin at low
  pinMode(IN0, INPUT);
}

void loop() {                             // Remolt:
  Serial.print(digitalRead(IN0));    // DEBUG ? IN0
  if (digitalRead(IN0) == HIGH) {
    ButtonA();                            //  IF (IN0 =1) THEN ButtonA:
  } 
  else {                                    // IN0 is NOT 1
    delay(25);                            // PAUSE 25
  }
}                                            // At end of loop automaticly goes to top of loop.

void ButtonA() {                       // ButtonA:
    delay(500);                         // PAUSE 500
    digitalWrite(4, HIGH);           // HIGH 4
    delay(200);
}                                           // Automaticly returns to where it comes from

You picked up some extra unicode characters when you copied and pasted it. The easiest way to gt rid of them that I have found is to post the code on this site in code tags. The site will reformat the code and remove all the unprintable characters. Then you can copy the code back out of the post and it will be cleaned of all those characters.

You do not even have to post if I recall correctly. Paste it in a new reply, go to preview and cut it; next paste in your sketch and get out of the new reply.

By the way, I tried to compile Gabriel's code and had no issues :wink:

sterretje:
You do not even have to post if I recall correctly. Paste it in a new reply, go to preview and cut it; next paste in your sketch and get out of the new reply.

By the way, I tried to compile Gabriel's code and had no issues :wink:

Never thought of preview. I forget that's there. I usually post it somewhere and then delete the post. Probably not the best move.

Time to look at your installation. If you have the windows app/store version, I suggest you uninstall it and download the version you find here. Just click software at top of page and select windows installer.

usabob01,

Please pay attention to how you quote. It's difficult to realise that there is a comment/question in reply #12.
Also please use code tags when posting code
[code]your code here[/code] results in

your code here

All I'm wanting is to write a sketch to when it sees a input pin go high then branch out to start my main code and just loop untill that pin goes high.

High and high?

Anyway, dig through the examples to learn. Ask if you don't understand something.

And some code for a simple button read and led on/off

const byte buttonPin = 2; // button connected to pin 2
const byte ledPin = 13;    // build in led

void setup()
{
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  if (digitalRead(buttonPin) == LOW)
  {
    digitalWrite(ledPin, !digitalRead(ledPin));
    delay(500);
  }
  else
  {
    digitalWrite(ledPin, LOW);
  }
}

Button wired between pin 2 and ground; LOW indicates that the button is pressed (due to this). The INTERNAL_PULLUP makes that the pin will not float and hence prevents random readings.

You can read output pins; digitalWrite(ledPin, !digitalRead(ledPin)) uses this. It writes the opposite value of what the output currently is (read the pin, invert the result and write it).

The result of above code is a simple blink commanded by a button press.

Now there are obviously problems with the above, especially the delay as you have to wait 500ms before the button is read again and action can be taken.