繁体   English   中英

将 Function C++ 转换为 Arduino [暂停]

[英]Convert Function C++ to Arduino [on hold]

您要更改为 Arduino 的代码:

string encryptDecrypt(string toEncrypt) {
  char key[3] = {'K', 'C', 'Q'};
  string output = toEncrypt;
  for (int i = 0; i < toEncrypt.size(); i++) {
    output[i] = toEncrypt[i] ^ key[i % (sizeof(key) / sizeof(char))];
  }
  return output;
}

有什么想法吗?

谢谢

    please try it .......

int main()
        {
               int sum;
               int answer;
               int correct = 0;
               int wrong = 0;
               int menu;`enter code here`
               int i;
               int j;

                srand(time(0));


               do {
                       cout << setw( 50 ) << "Kids Math Quiz Game!!!" << endl;
                       cout << setw( 49 ) << "**********Menu**********" << endl;
                       cout << setw( 44 ) << "[1] Addition " << endl;
                       cout << setw( 47 ) << "[2] Subtraction " << endl;
                       cout << setw( 40 ) << "[3] Exit " << endl << endl;
                       cout <<"Please enter your choice: ";
                       cin >> menu;

                       switch ( menu )
                       {
                        case 1:
                               i = rand()%10;
                               j = rand()%10;

                               if ((i<=1 && j<=9) || (i<=9 && j<=1))
                               {
                        cout << "What is " << i << " + " << j << " = ";
                                cin >> answer;
                                sum = i + j;

                                if( answer == sum )
                                  {
                                    cout <<"Great Job!!!!!" << endl << endl;
                                    correct++;
                                }
                                else
                                  {
                                    cout << "Sorry " << i <<" + " << j << " = " << sum <<endl << endl;
                                    wrong++;
                                }

                                cout << "You got " << correct <<" right and " << wrong << " wrong"<< endl<< endl;
                                cin.get();
                               }



*************************

#include <Keypad.h>

int sum;
int answer;
int correct = 0;
int wrong = 0;
int menu;
//int i;
//int j;
//long randNumber;
long i;
long j;

const byte ROWS = 4;  // four rows
const byte COLS = 4;  // four columns
char keys[ROWS][COLS] = {
 {'1','2','3','A'},
 {'4','5','6','B'},
 {'7','8','9','C'},
 {'#','0','*','D'}
};
byte rowPins[ROWS] = {8,1,2,4};  // Connect to the row pinouts of the keypad
byte colPins[COLS] = {3,5,6,7};  // Connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
byte ledPin = 13;

boolean blink = false;

void setup()
{
 Serial.begin(9600);    // Set up Serial library at 9600 bps
 pinMode(ledPin, OUTPUT);      // Sets the digital pin as output
 digitalWrite(ledPin, HIGH);   // Sets the LED on
 keypad.addEventListener(keypadEvent);  // Add an event listener for the keypad
}

void loop()
{
 char key = keypad.getKey();

 if (key != NO_KEY)
 {
   Serial.println(key);
 }

 if (blink)
 {
   digitalWrite(ledPin,!digitalRead(ledPin));
   delay(100);
 }
}

void keypadEvent(KeypadEvent key)
{
 //Serial.println(randomNumber);

 Serial.println("  **KIDS MATH");
 Serial.println(" QUIZ GAME!**");
 Serial.println("******MENU******");
 Serial.println("[1] Addition");
 Serial.println("[2] Subtraction");
 Serial.println("[3] Exit");
 Serial.println("Enter Your Choice: ");

 switch (key)
 {
   case '1':
           i = random(10);
           j = random(10);

           if ((i<=1 && j<=9) || (i<=9 && j<=1))
           {
             Serial.println("What is ");
             Serial.print(i);
             Serial.print(" + ");
             Serial.print(j);
             Serial.print(" = ");
             Serial.println(i + j);
           }`enter code here`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM