// Program: Ex1_VariableType-U.ino
/*
Exercise 1
Learn to use different types of variable
*/
void setup()
{
// Initialize serial and wait for port to open
Serial.begin(115200);
while (!Serial)
{
// Wait for serial port to connect, needed for native USB port only
}
}
void loop()
{
int a;
double b;
char c;
Serial.println(sizeof(a));
Serial.println(sizeof(b));
Serial.println(sizeof(c));
Serial.println(HIGH);
Serial.println(LOW);
Serial.println(LED_BUILTIN);
Serial.println(PI, 6);
Serial.println(INPUT_PULLUP);
// char type
Serial.print("Size of char is ");
Serial.print(sizeof(char));
Serial.println(" byte");
unsigned char minUchar = 0;
unsigned char maxUchar = 255; // try 256 here to see what is the printout
Serial.print("unsigned char value from ");
Serial.print(minUchar);
Serial.print(" to ");
Serial.println(maxUchar);
signed char minSchar = -128;
signed char maxSchar = 127; // try 128, 129 and 255 here to see what is the printout
Serial.print("signed char value from ");
Serial.print(minSchar);
Serial.print(" to ");
Serial.print(maxSchar);
Serial.println("\t CANNOT omit the \"signed\" word");
// int type
Serial.print("\nSize of int is ");
Serial.print(sizeof(int));
Serial.println(" bytes");
unsigned int minUint = 0;
unsigned int maxUint = 65535;
Serial.print("unsigned int value from ");
Serial.print(minUint);
Serial.print(" to ");
Serial.println(maxUint);
int minSint = -32768;
int maxSint = 32767;
Serial.print("int value from ");
Serial.print(minSint);
Serial.print(" to ");
Serial.println(maxSint);
// float type
Serial.print("\nSize of float is ");
Serial.print(sizeof(float));
Serial.println(" bytes");
float fexample1 = 12345678.12345; // too big for float
Serial.print("float example 1: ");
Serial.println(fexample1);
float fexample2 = 1234567.12345;
Serial.print("float example 2: ");
Serial.println(fexample2);
float fexample3 = -1234567.12345;
Serial.print("float example 3: ");
Serial.println(fexample3);
// double type
Serial.print("\nSize of double is ");
Serial.print(sizeof(double));
Serial.println(" bytes");
double dexample1 = 12345678.12345;
Serial.print("double example 1: ");
Serial.println(dexample1, 5); // print with 5 decimal places
while (1); // Dynamic halt of the program
}
/*
Size of char is 1 byte
unsigned char value from 0 to 255
signed char value from -128 to 127 CANNOT omit the "signed" word
Size of int is 2 bytes
unsigned int value from 0 to 65535
int value from -32768 to 32767
Size of float is 4 bytes
float example 1: 12345678.00
float example 2: 1234567.12
float example 3: -1234567.12
Size of double is 4 bytes
double example 1: 12345678.00000
*/