Shop OBEX P1 Docs P2 Docs Learn Events
Mystery Code — Parallax Forums

Mystery Code

jazzedjazzed Posts: 11,803
edited 2011-09-21 20:48 in Propeller 1
Will this ever run on Propeller?
Where does the example come from?
void setup(){
  Serial.begin(9600);
}

void loop() {
  int i = 2;
  int j = 3;
  int k;

  k = myMultiplyFunction(i, j); // k now contains 6
  Serial.println(k);
  delay(500);
}

int myMultiplyFunction(int x, int y){
  int result;
  result = x * y;
  return result;
}

Comments

  • HShankoHShanko Posts: 402
    edited 2011-09-20 11:18
    Have no idea where you got it, but looks to me like all the code is commented out with the '{', '}' brackets.
  • Mike GreenMike Green Posts: 23,101
    edited 2011-09-20 11:20
    It's Arduino code. It could be translated into Spin or FemtoBasic or PropBasic or Catalina C pretty trivially and run on a Prop.

    In FemtoBasic, it's functionally equivalent to:

    100 let i = 2
    110 let j = 3
    120 print i * j
    130 pause 500
    140 goto 120
  • jazzedjazzed Posts: 11,803
    edited 2011-09-20 11:23
    Translated is not "my" goal :)
  • Mike GreenMike Green Posts: 23,101
    edited 2011-09-20 11:32
    In that case, it's very unlikely that this code will run on a Propeller without changes any time soon. For a start, it requires a C++ compiler, not just a C compiler. None of the existing or proposed compilers for the Prop I or Prop II are for C++. It would also require an Arduino compatibility library in C++ ... not a big deal for the amount of code needed for this specific example, but a significant effort for the general case.

    I don't mean to say that it can't be done. The Arduino development system normally uses only a subset of the features of C++ that could be just as easily be compiled into Prop code as C and we already have two C compilers available with a 3rd on the way. There are some C++ to C compilers available, but it would take a bit of work to put everything together and make sure it works properly.
  • trodosstrodoss Posts: 577
    edited 2011-09-20 11:40
    @Mike,
    The GCC compiler porting effort (of which Jazzed is a part of) would most likely allow C++. However, emulating the Arduino's Analog I/O would be the bigger issue (most likely requiring extra hardware beyond just a Propeller). The code snippet posted probably could run--but not all of the Arduino code examples would. Don't get me wrong--I think it is a great idea! I just think, like Mike, that it will be pretty involved work.
  • Roy ElthamRoy Eltham Posts: 3,000
    edited 2011-09-20 11:40
    GCC = C++ as well as C.
  • AribaAriba Posts: 2,690
    edited 2011-09-20 14:26
    jazzed wrote: »
    Translated is not "my" goal :)

    Is GCC not just a form of a translater?

    Andy
  • Heater.Heater. Posts: 21,230
    edited 2011-09-20 14:49
    You can already run C++ code on the Propeller with Zog:)

    Can't see all the code in the code box on my Android phone here but I'm sure providing the Arduino class interfaces would not be such a major task.
  • jazzedjazzed Posts: 11,803
    edited 2011-09-20 16:18
    Heater. wrote: »
    You can already run C++ code on the Propeller with Zog:)
    I was wondering when you would mention that ;)

    Propeller GCC is already running C++ to a point. Things keep getting better everyday.
  • frank freedmanfrank freedman Posts: 1,983
    edited 2011-09-20 18:27
    Heater. wrote: »
    You can already run C++ code on the Propeller with Zog:)

    Can't see all the code in the code box on my Android phone here but I'm sure providing the Arduino class interfaces would not be such a major task.

    Just a matter of someone writing an appropriate library with arduino compatible interface spitting out the prop codes to do the intended functions provided they are within the capabilities of the prop hardware I would think.
  • RossHRossH Posts: 5,549
    edited 2011-09-21 03:12
    Heater. wrote: »
    You can already run C++ code on the Propeller with Zog:)

    Can't see all the code in the code box on my Android phone here but I'm sure providing the Arduino class interfaces would not be such a major task.

    No, not major - I believe the source for the Arduino libraries are all open source and freely available, and should be easily ported to the Propeller. However, I sincerely hope that all the time, money and effort Parallax is pouring into GCC has more ambitious goals than to simply turning the Propeller into yet another Arduino "wannabe" - the Propeller has so much more to offer than that!

    The Arduino has carved out a niche for itself that it (quite naturally) fits very well. And of course Arduinos are dirt cheap - I doubt any Prop-based board could compete with the low end Arduino boards on price. Worse - for most purposes where you might use an Arduino, the price/performance ratio would rule out both the Prop I (at the lower end), and the Prop II (at the upper end). I don't know the price of the latest ARM-based Arduinos - but I'd be willing to bet they'll be cheaper than any equivalent Prop II-based boards - and they'll be available sooner.

    The main problem with trying to compete with the Arduino is that it is perfectly suited for the kind of applications that it gets used for. The Propeller (I & II) both fit uncomfortably in the same space. For some types of applications they are simply not fast enough to compete, and for others their sophisticated capabilities are pure overkill, and also too difficult for people to use effectively - especially once you move beyond the world of simple (but very effective) IDEs and tools.

    This was one thing that both the Prop I and the Arduino got so right - their IDE is so simple that most people can just jump right in and get something running even if they have no programming background at all.

    Ross.
  • Dave HeinDave Hein Posts: 6,347
    edited 2011-09-21 05:57
    Ross,

    You make good points about the price/performance issue in the Arduino world. However, I think it would be useful for Prop users to be able to run Arduino code on the Prop. There are also cases where someone familiar with Arduino would like to try out the Prop. This would make it much easier for them to get familiar with the Prop. I suspect there are cases where the Prop provides the specific features that are needed for some applications, and there would be a need to run Arduino code on it.

    Dave
  • jazzedjazzed Posts: 11,803
    edited 2011-09-21 08:06
    RossH wrote: »
    However, I sincerely hope that all the time, money and effort Parallax is pouring into GCC has more ambitious goals than to simply turning the Propeller into yet another Arduino "wannabe" - the Propeller has so much more to offer than that!
    The goal is to provide Propeller users the world class GCC solution for professional development. Simpler hobbyist solutions will evolve from it. Having a highly respected solution is also useful in academia where acceptance leads to "permanent branding" and life long use by former students.

    The fact that Arduino also happens to use the GCC solution as it's key enabling technology is not lost on the objective reader.
  • RossHRossH Posts: 5,549
    edited 2011-09-21 20:48
    jazzed wrote: »
    The goal is to provide Propeller users the world class GCC solution for professional development. Simpler hobbyist solutions will evolve from it. Having a highly respected solution is also useful in academia where acceptance leads to "permanent branding" and life long use by former students.

    The fact that Arduino also happens to use the GCC solution as it's key enabling technology is not lost on the objective reader.

    Yes, I kind of figured this would be the response. Good luck with that. :)


    Post Edit: That sounded a bit sharp - just to clarify, I mean "Good luck with enticing hobbyist/Arduino users using this approach", not "Good luck with GCC" (which I believe is going quite well).
Sign In or Register to comment.