Questions tagged [sketch]

A sketch is compiled code that is uploaded to an Arduino board.

This tag should be used when writing code for the Arduino specifically using the Arduino IDE.

A sketch has the following structure:

void setup()
{
    ...
}

void loop()
{
    ...
}

The setup function is called once when the sketch starts. The loop function then is called repeatedly until the board is either shut down or restarted.

A sketch is saved with the .ino extension.


If you are used to more traditional C programming, effectively what is done by the above is:

int main ()
  {
  init ();  // set up hardware, particularly timers used by delay()
  setup (); // your own code, to be run once only
  while (true)
    loop ();  // do this repeatedly
  return 0;   // this is never executed
  }

It's a bit more complex than that, but that is the basic idea. Also the IDE lets you take control by writing your own main() function like this:

int main ()
  {
  ...  // do whatever you want here
  return 0;
  }

If you do that, the "normal" main is ignored.

258 questions
61
votes
7 answers

Is there any way to download a sketch from an Arduino?

I made a sketch, but then I lost it. However, I uploaded it to the Arduino before losing it. Is there any way I can get it back?
The Guy with The Hat
  • 5,232
  • 7
  • 29
  • 51
17
votes
6 answers

What happens if there is a runtime error?

What happens if there is a runtime error in a program? Will execution of the program just stop? Is there some way I can get the Arduino to tell me what the error is?
The Guy with The Hat
  • 5,232
  • 7
  • 29
  • 51
2
votes
1 answer

Leds become dimmer after they reach a certain brightness, why?

Even if I don't use buttons and I do an automated thing that makes the led brighter(Even the non-rgb one)after sometime it resets itself to a dimmer light, why?* int Gled = 5; int Bled = 6; int Rv; int Gv; int Bv; int b1 = 7; int b2 = 8; void…
David
  • 23
  • 3
2
votes
2 answers

How to program an offbrand arduino uno?

So I recently bought this off brand arduino uno from betemcu.cn. it says its r3 compatible. Can I program this thing with the arduino coder or do I need to use something else? whenever I try uploading the code it says "problem uploading to…
Corey Selby
1
vote
0 answers

I have 2 sketches with same RTC DS1307 but when I combine the 2 sketches it gives errors

I have 2 sketches one is pixel clock with RTC ds 1307 and the other is 7 Segment with DHT 11, I want to merge the two into one but it is giving errors for rtc. sketch for pixel clock #include #include #include…
1
vote
2 answers

What is wrong with my code? RGB potentiometer

Arduino programming has been a huge learning curve for me and I am trying to create a project with an rgb that's color is determined by a potentiometer. To where the further I turn it, the further across the rainbow spectrum it goes. I can't figure…
Harrison
  • 19
  • 1
1
vote
2 answers

Can an a Arduino make music or speech without a speaker?

I have an Arduino Leonardo that can turn a relay off and on and the click is audible on the relay -this is simply done by making one of the control wires HIGH in the program code to turn the relay on and make the same control wire LOW to turn the…
0
votes
2 answers

Why does this take more byte?

I am only replacing a portion of my code where I want to use the first method but as you can see it is making my sketch size little bigger //if(iBPM >= 40 || iBPM <= 170 ) { char iBPMwav[50]; String thisString = String(iBPM); …
0
votes
1 answer

Please explain the void loop() section of the sketch

#include int PWMB = 5; //Speed control void setup(){ Serial.begin(9600); //receiver setup vw_set_rx_pin(2); vw_set_ptt_inverted(true); vw_setup(2000); vw_rx_start(); } void loop(){ uint8_t…
laoadam
  • 45
  • 5
0
votes
1 answer

please explain the sketch attached

Sorry about a newbie. 1. what mening of: if(Xstr[XstrLength-1] != '|'){ Xstr[XstrLength] = '|'; Xstr[XstrLength+1] = '\0'; the setup: char Xstr[60]; what means? and then: itoa(Yint,Ystr,10); Code: #include…
laoadam
  • 45
  • 5
0
votes
2 answers

What does the following code in Morse Code Arduino mean?

struct node *root, *currentNode; root = (struct node*)malloc(sizeof(struct node)); root->value = '\0'; root->next = 0; currentNode = root;
0
votes
1 answer

How to extend my Sketch for Multiple Inputs and Outputs

I am using 4 Push Buttons and 4 leds in my project. Here the sketch is only for one push button and one Led. I want extend my sketch upto 4 push buttons and 4 leds .Please tell what changes I make in my sketch. Please any body can make changes in…
Gul Asfand
-3
votes
1 answer

questions about sketch

int k ; int q ; int f;//pot void setup() { pinMode(k, OUTPUT); pinMode(q, OUTPUT); pinMode(f, INPUT); } void loop() { zzf(); } void gf() { int a = f;//test the conditions of f and store in new variable int a if (a == 80)//if a reads 80…
jai
  • 1
  • 3
-5
votes
1 answer

String matching serial input (was Code for voice recognition for arduino uno)

#include // import the serial library SoftwareSerial Genotronex(10, 11); // RX, TX int ledpin=13; // led on D13 will show blink on / off int BluetoothData; // the data given from Computer void setup() { // put your setup code…