Shop OBEX P1 Docs P2 Docs Learn Events
C++ I/O with Propeller and SimpleIDE — Parallax Forums

C++ I/O with Propeller and SimpleIDE

dirtrider444dirtrider444 Posts: 33
edited 2013-01-11 13:30 in Propeller 1
Hello
I am trying to understand how to get my propeller board to do "Hello World" or (get an led to blink) with SimpleIDE. I found this code below on this forum but when I compile, it says the output is not declared along with the high and low definitions. I just finished my C++ class(we didnt do anything with a microcontroller) so this is fairly new to me. Any help would be appreciated!
Taylor


/* Blinking LED
*
*
* turns on and off a light emitting diode(LED) connected to a digital
* pin, in intervals of 2 seconds.
*
* Created 1 June 2005
* copyleft 2005 DojoDave <http://www.0j0.org&gt;
*
* based on an orginal by H. Barragan for the Wiring i/o board
*/
#include <iostream>
#include <cstdlib> // function generator for random number
#include <ctime> // starts system clock
using namespace std;
int ledPin = 13; // LED connected to digital pin 13
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop()
{
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}

Comments

  • mindrobotsmindrobots Posts: 6,506
    edited 2013-01-11 02:08
    You are trying to compile Arduino code for a Propeller?

    You don't have any libraries to provide Arduino like functions (pinMode, digitalWrite, setup, loop, etc.) to your C++ program.

    Which Propeller board are you using?

    Have you looked at any of the tutorials on the PRopGCC wiki?

    The LED toggle demo from teh PropGCC demos looks like this:
    /*
    This shows an example for creating an LMM program and Makefile.
    It simply toggles the pins at 1Hz rate.
    
    Copyright (c) 2011 Parallax, Inc.
    MIT Licensed.
    
    +--------------------------------------------------------------------
    ¦  TERMS OF USE: MIT License
    +--------------------------------------------------------------------
    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files
    (the "Software"), to deal in the Software without restriction,
    including without limitation the rights to use, copy, modify, merge,
    publish, distribute, sublicense, and/or sell copies of the Software,
    and to permit persons to whom the Software is furnished to do so,
    subject to the following conditions:
    
    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    +--------------------------------------------------------------------
    */
    
    #include "propeller.h"
    
    // this is a bit more elaborate than required, but
    // it shows usage of a basic C++ class
    class pinset {
    private:
      // these variables are not accessible outside the class
      unsigned int mask;  // which pins are in this set
      unsigned int freq;  // the frequency at which to toggle them
    public:
      // here are the public variables and methods
    
      // the basic constructor
      pinset(unsigned int m, unsigned int f) {
        mask = m;
        freq = f;
        DIRA |= m;
      }
    
      // the run loop
      void run(void) {
        for(;;) {
          OUTA ^= mask;
          waitcnt(freq+CNT);
        }
      }
    };
    
    int main(void)
    {
      // create a set of pins to toggle at 2Hz
      pinset allpins(0x3fffffff, CLKFREQ>>1);
    
      // now go and toggle them, forever
      allpins.run();
    }
    
    

    It does compile as a C++ program under PropGCC. I didn;t have a board handy to test it but there's no reason it shouldn't work if you have some LEDs properly connected to any pins on any propeller board.
  • dirtrider444dirtrider444 Posts: 33
    edited 2013-01-11 13:00
    @mindrobots - thank you very much for your response. I looked it up and it says I have a prop stick usb propeller. I tried running that code because I thought that being c++ code it might work but you were right on the money about no #include for the propeller. I compiled it through simpleIDE and it worked great!

    Thanks,
    Taylor
  • mindrobotsmindrobots Posts: 6,506
    edited 2013-01-11 13:30
    Glad it worked!

    Arduino code is C++ hidden behind some functions and libraries which are specific to the Arduino environment.

    If you are familiar with Arduino, there is Pellerduino which is an ongoing project to get the Propeller working under the Arduino IDE. If you aren't and generally in the long run, you're best off just learning how to use C++ and the Propeller libraries to start writing C++ code for the Propeller.

    There are a few scattered examples and demos of C++ code with the PropGCC package. There are also a few folks around the forums that are actively coding C++ using PropGCC and SimpleIDE. Hopefully, they'll chime in with some advice sometime soon.

    Good luck and have fun!!

    Feel free to ask questions, the folks around here are pretty darn friendly!
Sign In or Register to comment.