#include <Arduino.h>
#include <stdio.h>
#include <string.h>
struct Student
{
char name[12];
float gpa;
};
#define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
const char k1[7][15] = {
"set", // [0]
"get", // [1]
"clear", // [2]
"reset" // [3]
"read", // [4]
"write", // [5]
};
const char k2[6][10] = {
"function",
"wifi",
"ble",
"status",
};
const char v1[5][10] = {
"fillall",
"bright",
"effect",
"fade",
};
const char* k3[6][10] = {
"up",
"down",
"add",
"on",
"off",
};
const char* v2[10][15] = {
"rgb",
"red",
"green",
"blue",
"hue",
"saturation",
"fade",
"speed",
};
const char* Answers[4][10] = {
"no",
"yes",
};
////
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
struct Student student1 = {"Jimmy", 3.8};
struct Student student2 = {"Janet", 2.5};
struct Student student3 = {"Tommy", 4.0};
struct Student student4 = {"Aaron", 3.8};
struct Student students[] = {student1, student2, student3, student4};
for(int i = 0; i < sizeof(students)/sizeof(students[0]); i++) {
printf("%-10s", students[i].name); // % looks for variable | -12 owns next 12 characters beore anything else can print | s spacifies the variable typed string
printf("%.2f\n", students[i].gpa); // %f looks for variable | .2 prints 2 places to the right of the decimal | f specifies type float | \n ends the line and strarts a new one
}
char newName1[7] = "frank";
strncpy(student1.name, &newName1[0], strlen(newName1));
printf("%s\n", student1.name);
Serial.println("Student 1: "+String(student1.name));
char newName2[7] = "jessie";
strncpy(student2.name, &newName2[0], sizeof(newName2));
printf("%s\n", student2.name);
Serial.println("Student 2: "+String(student2.name));
char newName3[7] = "Elijah";
strcpy(student3.name, &newName3[0]);
printf("%-10s", student3.name); printf("I added space with -10 instead of using tab\n");
Serial.println("Student 3: "+String(student3.name));
char newName4[7] = "Klaus";
strcpy(student4.name, &newName4[0]);
printf("%s\n", student4.name);
Serial.println("Student 4: "+String(student4.name));
}
void loop() {
delay(10); // this speeds up the simulation
printf("Array Size of k1 %i\n", ARRAYSIZE(k1));
}
/*
OPUTPUT
Simulation
00:37.454
100%
ets Jul 29 2019 12:21:46
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:1156
load:0x40078000,len:11456
ho 0 tail 12 room 4
load:0x40080400,len:2972
entry 0x400805dc
Hello, ESP32!
Jimmy 3.80
Janet 2.50
Tommy 4.00
Aaron 3.80
frank
Student 1: frank
jessie
Student 2: jessie
Elijah I added space with -10 instead of using tab
Student 3: Elijah
Klaus
Student 4: Klaus
*/