MY C++ library with an aim to use on the mega2560

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi everyone.
So I bought an Arduino Mega 2560.
I was using it and started writing my own classes for it.
And then I read about programming AVR's in the eclipse IDE.
I have set that up and it works nicely.
However I wanted to write my own set of classes and start programming AVR's in C++. I understand C++ takes up more memory on AVR's than C, but on something as big as the 2560, I have read it is not such an issue.
I found a few classes lying around the internet for the mega8 so I have begun writing my code extending this.

So far I am quite pleased with how things are going, but I wanted to see if anyone could have a look and see if Im going drastically wrong anywhere because alot of my code I am porting from C and turning into C++ classes.
If anyone can, I would be very appreciative if they could look at my Button class, which is supposed to handle debouncing - although Im a little wary of my implementation, my Serial class - and perhaps some ideas on how to state which UART it is going to use so I dont have to write a whole class for each UART channel and how I could change the Timer class so that it was much more general - and it could handle any Timer (1,2,3).

Lastly I want to write a class to handle MIDI communication. It will rely on a Serial object to send the information but my serial class does not use interrupts. Should I use an interrupt based Serial class to handle the midi communication to keep timing very accurate?

Thanks
Alex

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I understand C++ takes up more memory on AVR's than C

That depends entirely on what C++ features you use. For many C++ features there is no extra cost at all.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

outb(), sbi()? Which century was this written in exactly?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys,
Thanks for your replies, Ive added a few more features, and fixed the old skool coding you mentioned in Timer2 class.
I've had to modify the way the debounce code works, just wondered whether someone could have a look - the problem was the way Timer2 class worked - you can only have one object of Timer2 obviously so I have to deal with it in main rather than in the button debounce, method - I suppose I could pass a reference, but my request is more to do with this being the first time I have tried to write a formal debounce method and would be great if someone could check it.

		static unsigned long last = timer.MsCur();
		static bool hasPassed = timer.HasElapsed(last, b.getDelay());
		if(b.getState(last, hasPassed) == Button::Pressed){

The other thing is I have tried to wirte a method for external interrupts
you pass in which interrupt (0 or 1 for mega8) and the status you want it to be in (rising/falling/low/any as 0,1,2,3) and that sets up the interrupt for you, but I wasnt sure what to do with the actualy interrupt routine. I was thinking of a public volatile flag that can be checked the state of, but wasnt sure how to get it to have the interrupt routine for both interrupt 1 and int 0 as part of the class. Any glancing comments would be appreciated there.

EDIT: Oops just noticed the unused variable "pin" being passed into the external interrupt class. doesnt affect anything, just dont want anyone getting confused as to why its there.

Attachment(s):