לימוד ארדואינו : שיעור 9 – מחרוזות המשך קורס C506
פתח את אתר https://wokwi.com/ והעתק את התוכנה
הוסף שני לדים לפין 8 ו ופין 12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
/* www.Robotronix.co.il c506 learn c */ #include <stdio.h> #include <string.h> // pins map #define GreenLed 12 #define RedLed 8 // strcmp if equal is 0 else not 0. //https://www.programiz.com/c-programming/library-function/string.h/strcmp char Password[5]; // 4 chars + 1 NULL =0 total 5 int j=0; char PasswordInput[5]; void setup() { pinMode(GreenLed, OUTPUT); pinMode(RedLed, OUTPUT); Serial.begin(9600); // open the serial port at 115200 bps: strcpy(Password , "8541"); // main password strcpy(PasswordInput , "8541"); // Password to be check Serial.println(); for(j=1;j<=4;j++) { digitalWrite(RedLed,HIGH); digitalWrite(GreenLed,HIGH); delay(100); digitalWrite(RedLed,LOW); digitalWrite(GreenLed,LOW); delay(600); } // end for j if(strcmp(Password,PasswordInput)==0) { // equal digitalWrite(GreenLed,HIGH); Serial.println("Password o.k"); } else { digitalWrite(RedLed,HIGH); Serial.println("worng Password "); } } void loop() { } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
/* www.Robotronix.co.il c506 learn c */ #include <stdio.h> #include <string.h> char Password[5]; // 4 chars + 1 NULL =0 total 5 int j=0; void setup() { Serial.begin(9600); // open the serial port at 115200 bps: strcpy(Password , "8541"); // main password Serial.println(); Serial.print("your password is : "); for(j=0;j<=3;j++) { Serial.print(Password[j]); } // end for j } void loop() { } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
char Password[10]; // 4 chars + 1 NULL =0 total 5 int j=0; void setup() { Serial.begin(9600); // open the serial port at 115200 bps: strcpy(Password , "8541"); // main password Serial.println(); Serial.print("your password is : "); for(j=0;j<=3;j++) { if (j<=1) { Serial.print("*"); } else{ Serial.print(Password[j]); } } // end for j } void loop() { } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
/* www.Robotronix.co.il c506 learn c */ #include <stdio.h> #include <string.h> char Password[10]; // 4 chars + 1 NULL =0 total 5 int j=0; void setup() { Serial.begin(9600); // open the serial port at 115200 bps: strcpy(Password , "63217794"); // main password Serial.println(); Serial.print("your password is : "); for(j=0;j<=strlen(Password);j++) { if (j<= strlen(Password)-3) // 0 , 1 { Serial.print("*"); } else{ Serial.print(Password[j]); } } // end for j } |