Pages: 1 2 [3] 4 5 ... 7   Go Down
Author Topic: Ardunio C++ SUCKS!!!!  (Read 9419 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Sr. Member
****
Karma: 7
Posts: 476
what?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I literally had to design each function by trial and error
I call that a learning curve and if you got it working i guess you learn't something.
Logged

0
Offline Offline
God Member
*****
Karma: 2
Posts: 854
Arduino rocks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't help feeling like I'm feeding a troll here, but if you really don't like C++, I suggest you look into JAL for the PIC microcontollers.   It's a pascal-like language but simplified for easy programming.  The developer has also created a bootloader, target boards and a set of modules he calls dwarf boards to add hardware, much like shields.  There are also picaxe devices you can look into which are pic microcontrollers with a BASIC intepreter/bootloader preinstalled.  That might be more your speed.

I actually came from JAL to Arduino about 6 years ago, specifically because I preferred the extra power and functionality C++ provided.  Things that were quite difficult in JAL such has dealing with timer interrupts and using the CCP module are trivial with Arduino.  Over the past 6 years I've been amaze at the quality and volume of libraries that have been donated to the Arduino project, but if you see the libraries as a hindrance you might be a lot happier in JAL.

If I have any complaint about Arduino it's that it's made everything so easy that even when I know a small program on a pic10F is the better way, I still go for the arduino out of laziness.

I do come from a computer science background so when you talk about the limitations of C++ you really do sound ignorant, I strongly suggest you read up on structured programming and why it's a good thing.  C++ also does allow you to use gotos, and I won't even say you shouldn't, but you better understand why most people say you shouldn't before you do.  C++, while being structured also does give you far more control over the flow of your program than most languages, it is extremely powerful, but with that power, it's also very easy to shoot yourself in the foot.
« Last Edit: August 03, 2012, 07:03:03 am by Oracle » Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 54
Posts: 1848
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Perhaps something like modkit (http://www.modk.it/) would be better for you than C++.  At least according to the blurb, it support Arduino, and other platforms.  It recently was a kickstarter project, and it should be getting into general availability now.
Logged

Tucson, AZ
Offline Offline
Sr. Member
****
Karma: 8
Posts: 317
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I bet if you just gave the 11 year old the Uno and Massimo's book, along with a basic supply of components, he would be flying along in no time.   Don't project your insecurities on him.  He will likely just embrace what is taught in Massimo's book as the way that things are done, particularly since he does not know, as you proclaim to, that it's "all wrong."
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A Netduino (http://netduino.com/netduino/) would be the best option for the OP. Program it with Visual Basic.

I agree about the eleven year old. Children pick up languages far quicker than adults do - spoken or programming.
Logged

Espoo, Finland
Offline Offline
God Member
*****
Karma: 7
Posts: 586
"Oops, try again..."
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I also have my past with Basic programming, more than 35 years.
When I got my arduino less than two years ago, my first day was a nightmare...,
next day I got blink code working, without understanding how it works. One day later,
I was ready to start with C, ready to convert my thinking into totally different
kind of structuring.

If only my english would be better, learning would be so much easier.
All I needed to start, almost, was found from the Arduinos reference.

That was my first contact with C programming.

Cheers,
Kari

PS. I nearly took to bait.
Logged


The only law for me; Ohms Law: U=R*I       P=U*I
Note to self: "Damn! Why don't you just fix it!!!"

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 627
Posts: 34239
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I understand the limited resources inside the UNO and the need for a language that is not too verbose.
Something else you don't understand. C is a compiled language so it matters not how verbose it is because it gets compiled into machine code before it is downloaded to the Arduino and then run.
Basic is an interpreted language, that means that each time a line is executed it has to be first turned into a machine language and then run.

The reason people wrongly thing there is an Arduino language is because there are functions someone has already written and packaged up for you to do the direct talking to the hardware and a bit of other stuff as well. So in a book on C++ you will not find any mention of digitalWrite() because it is a function someone has written. It is, however, possible to see the code for that function if you want to. It is just ordinary C code. Functions like this are well documented in the reference section of the help menu.

If you find the arduino hard then just try any other mcrocontroller system and you will soon be back here. It is the easiest way to write a generalised program. Forget about toy trucks, they are fine for moving the truck but you can't write a seven segment display routine in those, they are not so much programming systems but special purpose scripting machines.
Logged

0
Offline Offline
Full Member
***
Karma: 2
Posts: 156
It was all digital
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Less talk - more action.

Quote
The main program is in a loop looking for a start switch closure. It then calls a custom function (I guess that is a C++ subroutine??) that looks for one of four detector triggers or a stop switch closure, in a loop. Each detector trigger calls one of two different custom functions to energize and de-enrgize some relays. It then returns to the detection process. It only returns to the startup loop if it finds a stop switch closure in the detection process.

I dont's have Arduino, realys, switches at me ... but I did have 8 min left of my lunchbreak.
Code:
const int startSwitch = 12;  // Start switch
const int stopSwitch = 11;   // Stop switch
const int det1 = 10;
const int det2 = 9;
const int det3 = 8;
const int det4 = 7;

boolean running = 0;

void setup(){
  pinMode(startSwitch, INPUT);
  digitalWrite(startSwitch, HIGH);  // enable pull-up
  pinMode(stopSwitch, INPUT);
  digitalWrite(stopSwitch, HIGH);  // enable pull-up
  pinMode(det1, INPUT);
  digitalWrite(det1, HIGH);  // enable pull-up
  pinMode(det2, INPUT);
  digitalWrite(det2, HIGH);  // enable pull-up
  pinMode(det3, INPUT);
  digitalWrite(det3, HIGH);  // enable pull-up
  pinMode(det4, INPUT);
  digitalWrite(det4, HIGH);  // enable pull-up
  
  Serial.begin(115200);
}

void loop(){
  if (digitalRead(startSwitch) == LOW){  // Is it time to start?
    Serial.println("Starting");
    running = 0;
  }
  while (running){
    if (digitalRead(det1) == LOW){action1;}
    if (digitalRead(det2) == LOW){action2;}
    if (digitalRead(det3) == LOW){action3;}
    if (digitalRead(det4) == LOW){action4;}
    if (digitalRead(stopSwitch) == LOW){  // Is it time to stop?
      Serial.println("Stopping");
      running = 0;
    }
  }
}

// ****
void action1(){
  Serial.println("Action 1");
  delay(1000);
}

void action2(){
  Serial.println("Action 2");
  delay(1000);
}

void action3(){
  Serial.println("Action 3");
  delay(1000);
}

void action4(){
  Serial.println("All your base are belong to us");
  delay(1000);
}

Compiled but NOT testet.

-Fletcher

Edit: This code works as intended:
Code:
const int startSwitch = 12;  // Start switch
const int stopSwitch = 11;   // Stop switch
const int det1 = 10;
const int det2 = 9;
const int det3 = 8;
const int det4 = 7;

boolean running = 0;

void setup(){
  pinMode(startSwitch, INPUT);
  digitalWrite(startSwitch, HIGH);  // enable pull-up
  pinMode(stopSwitch, INPUT);
  digitalWrite(stopSwitch, HIGH);  // enable pull-up
  pinMode(det1, INPUT);
  digitalWrite(det1, HIGH);  // enable pull-up
  pinMode(det2, INPUT);
  digitalWrite(det2, HIGH);  // enable pull-up
  pinMode(det3, INPUT);
  digitalWrite(det3, HIGH);  // enable pull-up
  pinMode(det4, INPUT);
  digitalWrite(det4, HIGH);  // enable pull-up
  
  Serial.begin(115200);
}

void loop(){
  if (digitalRead(startSwitch) == LOW){  // Is it time to start?
    Serial.println("Starting");
    running = 1;
  }
  while (running){
    if (digitalRead(det1) == LOW){action1();}
    if (digitalRead(det2) == LOW){action2();}
    if (digitalRead(det3) == LOW){action3();}
    if (digitalRead(det4) == LOW){action4();}
    if (digitalRead(stopSwitch) == LOW){  // Is it time to stop?
      Serial.println("Stopping");
      running = 0;
    }
  }
}

// ****
void action1(){
  Serial.println("Action 1");
  delay(1000);
}

void action2(){
  Serial.println("Action 2");
  delay(1000);
}

void action3(){
  Serial.println("Action 3");
  delay(1000);
}

void action4(){
  Serial.println("All your base are belong to us");
  delay(1000);
}
« Last Edit: August 03, 2012, 09:50:26 am by Fletcher Chr » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26350
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
if (digitalRead(det4) == LOW){action4;}

Would be better to call the function smiley-wink
« Last Edit: August 03, 2012, 05:44:03 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Full Member
***
Karma: 2
Posts: 156
It was all digital
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It was a base safe code .....  smiley-grin

Would be better to change:
Code:
Serial.println("Starting");
    running = 0;

Into:
Code:
Serial.println("Starting");
    running = 1;
too smiley-razz

-Fletcher
« Last Edit: August 03, 2012, 09:48:27 am by Fletcher Chr » Logged

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

On the contrary ( to the original subject  )- Arduino Rocks !!

I am also an old fart ( 64 in your Earthling years ) who had come through valves ( tubes ) transistors, TTL and found myself stuck for 20 or more years at CMOS logic, scared to move further on than my Sinclair 32 computer.

Ok I played with a bit of basic, and I wrote a simple FORTRAN program on a course in 1968, but just couldnt get into the micro scene - until I found Arduino in 2010 !

Now I am building all sorts of ambitious projects that tax my lateral thinking, but thank heavens for the guys on the forum that point out the brain farts in my code.

The project I finished today, I could never have contemplated in my CMOS days  -   A queueing system with a GPS receiver, thermal printer, 2.4 GHz link to a data logger ( SD card ) which also receives and logs data from 6 remote controls via a 433 MHz link ( which also has to be displayed on a LED dsiplay )
 I came up with my own system to save data to eeprom on all the units if the power goes down - probably twice as complicated as what might be available doing a search, but it works great and brings me so much satisfaction !

So I think that what SUCKS !!!!! was my reluctance to get into micros all this time, and what ROCKS !!! is the gateway that these Italian guys thought of in a bar called Arduino ,   Grazie per l'introduzione di microprocessori !!!

Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

0
Offline Offline
Faraday Member
**
Karma: 24
Posts: 3488
20 LEDs are enough
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The basic problem is that to keep cost and power requirements low, we are working on an 8 bit controller here with a small amount of static RAM and a small amount of program space.  The language needs to take that into account.  It can't produce 100K files for a Hello World application like a Windows compiler does.  The only good language choices are assembler, C, and C++.

I would just like to point out that Forth would fit these requirements just as well. Sometimes Forth actually beats C/C++ a lot. However C/C++ is much more main stream.
Logged

Check out my experiments http://blog.blinkenlight.net

South Texas
Offline Offline
Edison Member
*
Karma: 8
Posts: 1025
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

C and C++ are pretty much main stream and C provides both High level and Low level access to the underlying machine. It is a TYPED language, but less strongly than Pascal and Basic which in turn allows us to do some of our quick and dirty conversions without having to create more variables and functions. If I don't use it regularly I do find that I have to go back to the reference, but that is not a major problem.

There is an AVR Basic out there, but it looks like you will have to pay real money for it and I don't think it is as easy to use as Arduino.

C Has functions and procedures - a procedure in C is just a function that doesn't return anything. - i.e. void MyFunc(int Whatever) and the other form that would be a function in other languages looks like this - int AnotherFunc(int Whatever). As in any language there are rules of grammar (syntax) that you must become familiar with. C was originally intended to be a system programming language, and the creators assumed the programmer would have some idea what he was doing and they made it easier to do some things, but that also means there are ways to get in trouble...

It happens with natural languages also - I grew up speaking American English. Listening to a Brit or Aussie can be incredibly confusing, and I suppose they feel the same about us Yanks. Even the USA Aluminum and the Canadian Aluminium can sometimes throw folks off. And I am trying to learn Spanish, at 54 years old. And no, I don't gripe at the folks in Mexico about how stupid or out of date or whatever their language is. I work at trying to communicate with what they understand. And a programming language is magnitudes easier to learn than is a natural language. I have learned BASIC, Pascal, C, at least 3 versions of Ladder Logic along with a couple of batch programming languages. There is a learning curve and initially it is rather steep, but for most computer languages the plateau is not very high.
Logged

Hesperia CA
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, you convinced me I was whining but there is an explanation:

To start out with the recommended tutorial at cplusplus.com was what I needed all along. It explained it all in adequate detail so that I could understand it. I'm not stupid but just did not want to spend a semester in a C++ class to get enough info to do my one time project and be able get the grandson started right without bad or incomplete info from me. I have it now. I'll leave doing a C++ class to my grandson.

Next the books I referenced and the tutorial I used on the Arduino.cc site were just not detailed enough or could not be extended enough to do my task. The Tutorial I was sent to,

http://www.cplusplus.com/doc/tutorial/

was excellent and a good complete reference for C++. I went through it in a couple of hours to gather the info I need and it is all clear. But the other books and tutorial were not complete enough. You'd think that between two books and the tutorial on this site there would have been enough info but there was NOT.

By trial and error before coming here I was able to get my little program to compile and a testing process is anticipated when I get my Relay card in the mail. But my frustration was that I kind of tried everything (with some limited working knowledge of programming in other languages) until it compiled and I wanted to know why. The Cplusplus web page tutorial was exactly what I needed.

I apologize if I offended anyone but while you all defended C++, you taught me many lesson which at the time I did not appreciate but now do. But do realize that walking into C++ from Basic is a shock. I doesn't flow like Basic at all, contains new and nondescript names, and is frustrating to use if you don't understand the syntax and the details of the language. This is especially true if the documentation at hand is not complete or you don't happen to find the "right" tutorial on the internet. I'm good now and thank you all. I know most of you are long time C++ programmers and have had a hard time understanding my frustrations. Can you think back for a moment to your first encounter with C++? Did the concepts just fall into your hands?. Did you have some better help than I got initially from the two less than adequate books and an incomplete tutorial listed on this site? OK? There is nothing worse for a person trying to use a new computer language than compiler errors that are described in terms they don' t understand. That was the impetus of the generation of this thread by me.

Thanks again, all,
LDBennett



Logged

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thats great, perhaps you could get to adding some help for newbies from the same background experience ?

When I get a chance, I want to post a couple of things for techies from my " soldering iron" background , explaining why pin2 is actually pin 4, and pin 28 can be analog 5 or digital 19 ( took me a while ) and so on.
« Last Edit: August 03, 2012, 05:19:01 pm by Boffin1 » Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Pages: 1 2 [3] 4 5 ... 7   Go Up
Jump to: