How do I implement tone() and noTone() for the Arduino Due? - c

As it turns out, noTone() and tone() are in the core arduino API, but seemingly not implemented for the Arduino Due. I was hoping to use tone() and noTone() to implement the mario death sound found here, but when I add the code and compile it, I get the following errors:
trenchRun:154: error: 'tone' was not declared in this scope
trenchRun:156: error: 'noTone' was not declared in this scope
In case you're interested, here's an SSCCE, compiled against Arduino 1.5.4 on Mac OS X 10.8:
void setup() {
// put your setup code here, to run once:
}
void loop() {
tone(1, 12345, 1000);
}
sketch_oct24a.ino: In function 'void loop()':
sketch_oct24a:7: error: 'tone' was not declared in this scope
Since I have an Arduino Due, I am limited in using Arduino 1.5.4.
How do I implement the tone() and noTone() functions for the Due?

Yes it seems that it is still disabled in the current version.
A quick search on the Arduino forum got me this : Arduino Due and tone()
I can't test their code but it seems that the guy found a pretty decent solution to make his own tone().
Have a look and tell us if it's working good.
Hope it helps! :)

Related

ISR declaration for LPC2148 in gcc compiler

I am new to gcc compiler and I am trying to compile code for LPC2148 using gcc compiler on mac m1. As per suggestions by some answers, I am using attribute((interrupt("IRQ"))) instead of __irq.
When I am compiling, there is no error and hex file is getting generated. However, the code written in interrupt Service Routine is not at all executing.
Can some one please help me here. I am completely fed up by searching solution for this.
Thankyou :)

Compiling Error with interrupt service routines for ATtiny using xc8

I am working on a project using an ATtiny 202 and I am nearly done with my programming, but I have run into a large problem. I can't create any ISRs, because I always get a compiler error.
I am using the newest version of MPLABX IDE (5.35) (yes it is for pic and avr mcus) and the second newest version of the xc8 compiler (v2.10). I cannot use the newest version of the compiler, because that is for some reason missing the device header for the ATtiny 202. (I had a different thread about that problem a while ago)
I have created the ISRs exactly like described in the XC8 Manual, and the IDE doesn't mark it as a problem either, but when I then try to compile the program I always get a compiler error.
Here is one of my ISRs:
void __interrupt (RTC_PIT_vect_num) pit_int(void){
onPIT(); //Run the function
RTC.PITINTFLAGS = 0x0; //and clear the interrupt flags
}
The IDE marks the RTC_PIT_vect_num blue and correctly recognizes it, as it is defined in the device header.
When I try to compile it, I get this error message, and the build fails:
main.c:864:19: error: expected declaration specifiers or '...' before numeric constant
void __interrupt (RTC_PIT_vect_num) pit_int(void){
^
I dont know what exactly the problem is and how to solve it.
For comparison, here is an example from the "XC8 User Guide for AVR", page 83:
void __interrupt(SPI_STC_vect_num) spi_Isr(void) {
process(SPI_SlaveReceive());
return;
}
As you can see, the structure of the function is exactly the same as in my own ISR.
Does someone have an idea what the problem is or may be and how to fix it?
Fixed:
I had posted this question on the microchip forum as well, as no one here seemed to be able to help.
So I figured out that the problem was that in the project properties under
XC8 Global Options -> XC8 Compiler -> Option categories: Preprocessing and messages
the option "Use CCI Syntax" was disabled. This needs to be enabled for the __interrupt to work.

What does the Serial method do? [Arduino]

I'm translating a program about an RFM Hopper Transmission from Arduino to C, but I'm stuck with the method Serial, since I don't exactly know what it does.
It only appears in the following line, inside the main of the program.
Serial.begin(115200);
I've searched online through the documentation of Arduino and only understand that it's used for comunication between the Arduino board and the other devices.
If cannot use it in my C program though, what am I missing?
https://www.arduino.cc/reference/en/language/functions/communication/serial/
If I can explain anything with more detail from my project please feel free to ask.
Serial is an object, predefined in the Arduino environment, which is in C++ (not C )
To use it, you should call Serial.begin(<baud>); in the setup() function of the Arduino environment, then you can use any method of Serial or the underlying base class
Stream

How can I use sound and nosound function in code blocks

I have used sound and no sound function in turbo C++, but I cannot get it to work in code blocks compiler.
Program:
int main()
{
sound();
delay();
nosound();
return 0;
}
I have added definition for delay and it's working in other programs.
When I am compiling this code I am getting error as ::undefined reference to sound and no sound.
How can I make this work? Or is there a different solution I should use?
You can use "Beep" function which is in windows.h header file.
In Beep function you have to give 2 parameters , first is for frequency and second is duration in milliseconds.
You can '\a' which gives alert sound, '\a' should be placed in printf.
I'm doing this right now! But i'm using C, dunno if for C++ is the same.
The only thing i know is that you have to include the library dos.h to make it work.
the function is Beep(soundfrequency,delay);
give it a try with Beep(2000,2000);
Good luck :)

BIOS interrupt _int86

I'm trying out some old code frome the book "Black art of 3d game programming". I know it is outdated but I started reading it and it's kind of fun and interesting. I downloaded the OpenWatcom C Compiler and made a new DOS Project in order to get this old code even compiled. I already compiled on piece of code where Videomode int13h is set and then I was able to draw pixels to the screen. But this was done with a C function called _setvideomode(). In the following example the videomode is set via the _int86 function which makes the interrupt call and the prototype should be in bios.h, but OpenWatcom says: No prototype found for function _int86. I am stuck now and don't know what to do ;) Here is the code:
void setGraphxMode(int mode){
union REGS inregs,outregs;
inregs.h.ah = 0;
inregs.h.al = (unsigned char)mode;
_int86(0x10,&inregs,&outregs);
}
int main(){
return 0;
}
Would appreciate any advise on this and yes I know: Graphics are done via DirectX or OpenGL these days. This is just for learning purpose! Thank you :)
Under OpenWatcom the call you are looking for is int386 I believe:
int386(0x10, &inregs, &outregs);

Resources