Code Writing Assistant

by Dean04150117 in Circuits > Arduino

135 Views, 1 Favorites, 0 Comments

Code Writing Assistant

IMG_3533.JPG

Premise: This code writing assistant project focuses on the efficiency during code writing, which people who are writing codes will save a lot of time when using the code writing assistant. To use the assistant, simply connect the assistant to your computer; there will be 3 buttons on the assistant, which each of them represents for loop, scanf, and printf. When the user press one of the button out of three, the format of the three codes will automatically be copied onto your code writing app, which users will no longer need to type each for the word out on code writing app. This assistant can definitely save a lot of time during code writing and improves your overall workflow.

Users: This code writing assistant is specialized and specifically designed for programmers, which is the reason why I picked the 3 common codes - for loop, scanf, printf - that a lot of programmers will be using during the process of coding. With this assistant, programmers will no longer need to type out each words and the format of the 3 codes, which the code will be pasted onto their code writing program within 1 second after you press the button.

How to use: There will be three buttons containing in the design, which each of the buttons will be marked with the three codes: for loop, scanf, and printf. Users can choose which code they want to paste and press the button. The code will be automatically pasted on the coding app when the users press the button, and the code will also be formatted.

Conclusion: To conclude, this code writer assistant is a convenient tool to use during coding, which can definitely save programmers a lot of time. Furthermore, the operation of the code writing assistant is easy, which the only action that users need to do is just press the button.

Prepare Supplies

IMG_3524.JPG
IMG_3523.JPG
IMG_3525.JPG
IMG_3526.JPG

1. Arduino Leonardo

2. 3 Buttons

3. Wires

4. Cardboard (decoration)

5. Breadboard

Set Up the Hardware for the Code Writing Assistant

Screen Shot 2021-05-10 at 12.47.42 PM.png
Screen Shot 2021-05-10 at 12.42.04 PM.png
Screen Shot 2021-05-10 at 12.50.19 PM.png
IMG_3524.JPG

1. Connect the positive and negative charge from Arduino Leonardo to the breadboard using wires.

2. Connect the wire from the positive charge to one side of the button.

3. Connect the other side of the button to the resistor.

4. Connect the negative charge to the resistor.

5. Lastly connect the button to slot D2. (See picture 1)

6. Repeat all of the steps for the rest of the 3 slots, which are D3, and D4.

7. After connecting all the buttons, use the USB wire to connect to the computer.

Setup the Code for the Code Writing Assistant

1. This is the code setup for the code writing assistant

Arduino Link: https://create.arduino.cc/editor/dlm0117/79cc7e1f-2b35-486e-ac5e-496703835a3e/preview

#include <Keyboard.h>

/*
 These core libraries allow the 32u4 and SAMD based boards 
 (Leonardo, Esplora, Zero, Due and MKR Family) 
 to appear as a native Mouse and/or Keyboard to a connected computer.
 */

void setup(){  // put your setup code here, to run once:
  pinMode( 2 , INPUT);   // sets the digital pin as input
  Keyboard.begin(); // initialize control over the keyboard
  Keyboard.releaseAll();

  pinMode( 3 , INPUT);   // sets the digital pin as input
  pinMode( 4 , INPUT);   // sets the digital pin as input
}

void loop(){  // put your main code here, to run repeatedly:
  if (digitalRead( 2 )) {

    pinMode(2,INPUT_PULLUP); //make pin 2 an input and turn on the pullup resistor so it goes high unless connected to ground
    if(digitalRead(2)==LOW){  // do nothing until pin 2 goes low
      Keyboard.print("for(int x=0; x<n; x++)"); //Send the message
      Keyboard.println();
      Keyboard.print("{"); //Send the message
      Keyboard.println(); //the key to press (ASCII code)
      
    }
  }
  if (digitalRead( 3 )) {

    pinMode(3,INPUT_PULLUP); //make pin 3 an input and turn on the pullup resistor so it goes high unless connected to ground
    if(digitalRead(3)==LOW){  // do nothing until pin 3 goes low
      Keyboard.print("scanf("); //Send the message
      Keyboard.print("\""); //Send the message
      Keyboard.print("%"); //Send the message
      Keyboard.print("d"); //Send the message
      Keyboard.print("\""); //Send the message
      Keyboard.print(","); //Send the message
      Keyboard.print("&"); //Send the message
      Keyboard.print("x"); //Send the message
      Keyboard.print(")"); //Send the message
      Keyboard.print(";"); //Send the message
     
    }
  }
  if (digitalRead( 4 )) {

    pinMode(4,INPUT_PULLUP); //make pin 4 an input and turn on the pullup resistor so it goes high unless connected to ground
    if(digitalRead(4)==LOW){  // do nothing until pin 4 goes low
      Keyboard.print("printf("); //Send the message
      Keyboard.print("\""); //Send the message
      Keyboard.print("%"); //Send the message
      Keyboard.print("d"); //Send the message
      Keyboard.print("\""); //Send the message
      Keyboard.print(","); //Send the message
      Keyboard.print("x"); //Send the message
      Keyboard.print(")"); //Send the message
      Keyboard.print(";"); //Send the message
      

    }
  }
}


Cover Up and Decorate the Code Writing Assistant

IMG_3534.JPG
IMG_3535.JPG

1. Cut the cardboards into the shape that covers up all the parts of Arduino Leonardo

2. Cut out 3 circles that the size is enough for the buttons to fit

3. Stick the cardboard onto Arduino Leonardo to cover it up

4. Insert the 3 buttons into the 3 holes so that they are exposed to outside of the box

5. Cut a small hole for the USB port

6. After covering all of the board, write down for, scanf, and printf beside the button that corresponds to the words

Connect the Code Writing Assistant to Your Computer

IMG_3543.JPG

How to Use

1. Connect the USB wire to your computer

2. While you are writing your code, choose from the 3 codes: for loop, scanf, and printf

3. Click the place that you want to insert your code in

4. Press the button to paste the desired code on the place you want to insert

Results (Video)

Code writing assistant