-
Notifications
You must be signed in to change notification settings - Fork 3
Matemáticas al poder!
gism edited this page Feb 1, 2015
·
1 revision
Ejemplos sacados de http://www.ladyada.net/learn/arduino/
/*
* Math is fun!
*/
int a = 5;
int b = 10;
int c = 20;
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Here is some math: ");
Serial.print("a = ");
Serial.println(a);
Serial.print("b = ");
Serial.println(b);
Serial.print("c = ");
Serial.println(c);
Serial.print("a + b = "); // add
Serial.println(a + b);
Serial.print("a * c = "); // multiply
Serial.println(a * c);
Serial.print("c / b = "); // divide
Serial.println(c / b);
Serial.print("b - c = "); // subtract
Serial.println(b - c);
}
void loop() // we need this to be here even though its empty
{
}/*
* Math is fun!
*/
#include "math.h" // include the Math Library
int a = 3;
int b = 4;
int h;
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Lets calculate a hypoteneuse");
Serial.print("a = ");
Serial.println(a);
Serial.print("b = ");
Serial.println(b);
h = sqrt( a*a + b*b );
Serial.print("h = ");
Serial.println(h);
}
void loop() // we need this to be here even though its empty
{
}/*
* Drive size calculator!
*/
int drive_gb = 5;
int drive_mb;
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.print("Your HD is ");
Serial.print(drive_gb);
Serial.println(" GB large.");
drive_mb = 1024 * drive_gb;
Serial.print("It can store ");
Serial.print(drive_mb);
Serial.println(" Megabytes!");
}
void loop() // we need this to be here even though its empty
{
}Ejercicio 1. Modificar el código para que se puedan introducir por puerto serie los tamanos