Pages: 1 ... 3 4 [5]   Go Down
Author Topic: Help with LED Lamp concept.  (Read 6634 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 4
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

I don't want to discourage you and understand that you've commited alot of time, effort and expense to see your project through.  But the fact is, your example code does impliment bitmath, vectors and other methods that some may argue are overkill for controlling a small number of LEDs.  Furthermore, bitmath is usually pretty difficult for most beginners to grasp.  Bitmath has sent many students home packing... smiley

 I did a quick look on the NET for a simpler project for you to consider.  You could still impliment a button to switch to different modes, one of which is color fading.
http://elenamuse.wordpress.com/2012/11/06/rgb-mood-light-arduino-project/

As for recommending books and such, I believe its up to the person to decide what they want to learn and study.  There is a vast section on education in these forums you look at and ask at, start from there.  Its also tough for us to offer suggestions as we really don't know what your level of understanding on this subject matter is.  If it's as low as you say, then pretty much and any beginners level material is good.


 



Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



As for recommending books and such, I believe its up to the person to decide what they want to learn and study.  There is a vast section on education in these forums you look at and ask at, start from there.  Its also tough for us to offer suggestions as we really don't know what your level of understanding on this subject matter is.  If it's as low as you say, then pretty much and any beginners level material is good.

As always thanks for your input. I have been doing a little research on what path I should take as far as learning a program language and I hit a snag.

I know that the Arduino is based of the C (or is it C++ Language) so my question is this.

Should I start with learning C and then move on to C++. Or, should I start with C++ and not do C.

Aslo, I have not looked at the link you sent, I will when I get home tonight. But I wanted to say thanks for posting it.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would recommend learning C then C++ as an easier path, but that is just how I came to know the languages. I don't try and write any C++ features in my code but of course use most of the arduino libraries that do use C++ features. As the name implies C++ built on top of the C language (C plus stuff) so most all of C functions and statements work in a arduino sketch.

Lefty
Logged

Valencia, Spain
Online Online
Faraday Member
**
Karma: 150
Posts: 5645
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

As for recommending books and such, I believe its up to the person to decide what they want to learn and study. 

It's very difficult to recommend books because everybody learns in a different way. This is especially true for complex subjects like programming.

Also, I haven't read any 'beginner' books since the 1980s and I'm sure there must be some newer ones published since then.

Should I start with learning C and then move on to C++. Or, should I start with C++ and not do C.

On a desktop machine I'd say NO in the biggest font available. In C++ you want to be using STL, smart pointers, RAII, etc., so that memory management is automatic and you never have any of the problems that C is famous for.

On the Arduino, though, you shouldn't really be doing ANY of those things. Arduino coding needs a careful selection of the appropriate features of C++ and I doubt there's a book that does this.

(Actually, all C++ coding needs a careful selection of the features of C++...there's some things you should never use)

None of this is helpful, I know.

At the end of the day I'm still going to say "don't learn C, learn C++". If you learn C first you'll pick up some bad habits that might need to be unlearned later. Missing out C++'s 'classes' in particular would be a bad move. Concentrate on things like syntax, program flow, basic data types (int, long, etc.). Ignore anything that uses "dynamic sizes".

Also look for stuff on how CPUs work. Getting a clear picture in your head of what bits and bytes are, what RAM is, how CPUs do their thing is very important.

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Valencia, Spain
Online Online
Faraday Member
**
Karma: 150
Posts: 5645
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I would recommend learning C then C++ as an easier path, but that is just how I came to know the languages. I don't try and write any C++ features in my code but of course use most of the arduino libraries that do use C++ features.

Learning a few C++ features and using them can make many coding jobs far neater/easier/safer.

eg. An RGB LED. If you've got several of them attached it makes far more sense to create a LED 'object':

Code:
class RGB_LED {
  byte reg,green,blue;
  void setBrightness(byte b) {
  }
  void setHue(int h) {
    // Set the color using a 'hue' value...
  }
  ...etc.
};

// Then you can have lists of them

RGB_LED frontLeds[8];  // 8 RGB leds at the front
RGB_LED rearLeds[8];   // 8 RGB leds at the rear

How would you write that in C?

Code:
byte frontLeds[8][3];  // 8 RGB leds at the front

void setHue(byte led[], int h)
{
  //  .. ?
}

Surely that sort of pointer manipulation isn't something we should encourage when you're using a C++ compiler.
Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Surely that sort of pointer manipulation isn't something we should encourage when you're using a C++ compiler.

I'm sure your right. It's just I don't 'think' in C++ so don't even consider how to perform a given task using non C features. I realize I'm using C++ features when I use the serial library functions but that's not the same as building such functions from scratch. I usually find a way to accomplish what I'm trying to do sticking with C and as I code for my personal retirement hobby only it's not a restriction that I feel.

 Digital and analog electronics hardware is where my past employment experience and education was grounded in, software is just the BS I have to put up with to get stuff working like I want.  smiley-wink

Lefty
« Last Edit: March 05, 2013, 02:41:14 pm by retrolefty » Logged

Offline Offline
Newbie
*
Karma: 4
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

fungus' original recomendation was you learn some general coding. You should be advised that the question you've asked is a really tough one to answer, likely to recieve alot of varied feedback.  I agree with Retrolefty's suggestion with some caveats.   C is probably better to learn first if you will just be programming the arduino.  If you wanted to write programs for other things, like computers or phones etc. it's arguably not the best option.

Learning C first is fine as long as you understand that switching to C++ down the road will require that you change the way "you think about designing making your programs work."  Which can be really tough for some people as it imposes a bunch of new rules that are hard to make sense of at first...  These new rules tend to make it a more powerful language because you can manage Complex programs easier and thus is more productive.  So if you do end up learning C first, always keep that in mind and don't forget it.  You may want to do a bit of research on the differences between the languages and their "programming paradyms", then make a decision. One final thought to consider- today, many microcontrollers like the arduino are still generally limited by its resources which is why C is so widely used.  In the coming years as the MCUs continue to evolve you may see a greater shift to Object Oriented design.  Again, these are just my personal opinions and recommendations.  
Logged

Valencia, Spain
Online Online
Faraday Member
**
Karma: 150
Posts: 5645
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Learning C first is fine as long as you understand that switching to C++ down the road will require that you change the way "you think about designing making your programs work."

Yep. That's why I think it's better to learn C++ first.

C++ has a lot of little, non-obvious advantages that add up to quite a lot. Classes+objects in particular.

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh my head hurts.  lol

No really thanks for all the input. I found a course on lynda.com the goes over both just to get you started.

I am going to look over it and see.  As far as my plans for programming, well its only for the Arduino.  I am Network engineer and IT manager, I have no plans on
Becoming a programmer. This is all just for fun.

I may go over the code I have now and see I can dumb it down so I can finish my Lamp though

Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 361
Posts: 17301
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh my head hurts.  lol

No really thanks for all the input. I found a course on lynda.com the goes over both just to get you started.

I am going to look over it and see.  As far as my plans for programming, well its only for the Arduino.  I am Network engineer and IT manager, I have no plans on
Becoming a programmer. This is all just for fun.

I may go over the code I have now and see I can dumb it down so I can finish my Lamp though



Well to continue on the thought, do realize that C is a proper subset of C++ so you are not having to 'switch' to anything or 'unlearn' anything to after mastering C to start learning and utilizing the features that C++ adds to the language.

Lefty
Logged

Offline Offline
Newbie
*
Karma: 4
Posts: 37
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Lefty,

Quote
Well to continue on the thought, do realize that C is a proper subset of C++ so you are not having to 'switch' to anything or 'unlearn' anything to after mastering C to start learning and utilizing the features that C++ adds to the language.

I'm going have to strongly disagree with that statement.  I know when I personally had to make that Paradym Shift it was extremely difficult, and it was for many other programmers too.  I only bring this up as I don't want someone who has asked us for help to be potentially misled by trivializing the difficulty in the "switch" for some people.

One of the well known books I read to begin learning C++ explains the challenges here:

http://books.google.ca/books?id=eC-iLe_iET8C&pg=PA10&dq=c%2B%2B+primer+plus+unlearn+c&hl=en&sa=X&ei=8ok2UdmBGJTa2wWqmoDIAg&ved=0CDEQ6AEwAA


Logged

Valencia, Spain
Online Online
Faraday Member
**
Karma: 150
Posts: 5645
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Well to continue on the thought, do realize that C is a proper subset of C++ so you are not having to 'switch' to anything or 'unlearn' anything to after mastering C to start learning and utilizing the features that C++ adds to the language.

I'm going have to strongly disagree with that statement.

Me too. It's a common belief among C programmers but it's not really true.

C++ isn't "C with extra stuff" when that "extra stuff" makes up 90% of the program.

Logged

No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

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