Python and C++

Introduction: Python and C++

#include
#include
#include

int _name ;
// For these LCD controls to work you MUST replace the standard LCD library from...
// https://github.com/marcoschwartz/LiquidCrystal_I2C
// Direct download https://github.com/marcoschwartz/LiquidCrystal_I2C/archive/master.zip
// Your project will not compile until this is done.
LiquidCrystal_I2C lcd_I2C_27(0x27,16,2); // set the LCD address for a 16 chars and 2 line display
/*
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( 13 , INPUT); // sets the digital pin as input
lcd_I2C_27.init (); // initialize the lcd
lcd_I2C_27.backlight();
pinMode( 5 , INPUT); // sets the digital pin as input
Keyboard.begin(); // initialize control over the keyboard
Keyboard.releaseAll();

pinMode( 6 , INPUT); // sets the digital pin as input
pinMode( 7 , INPUT); // sets the digital pin as input
_name = 0 ;

}

void loop(){ // put your main code here, to run repeatedly:
if (digitalRead( 13 )) {
_name = ( _name + 1 ) ;
lcd_I2C_27.clear();
}
if ( _name == 0 ) {
lcd_I2C_27.setCursor(0 , 0) ; // set the cursor, counting begins with 0
lcd_I2C_27.print( "PYTHON" ); // Print a message to the LCD.
python();
}
if ( _name == 1 ) {
lcd_I2C_27.setCursor(0 , 0) ; // set the cursor, counting begins with 0
lcd_I2C_27.print( "C++" ); // Print a message to the LCD.
C();
}
if ( _name == 2 ) {
_name = 0 ;
}
delay( 270 ); // waits a few milliseconds
}

void python() { //customised function
if (digitalRead( 5 )) {

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("if :"); //Send the message
}
Keyboard.releaseAll();
for (int j = 0 ; j < 2 ; ++j ) {

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.press(216); //the key to press (ASCII code)
}
Keyboard.releaseAll();
}
}
if (digitalRead( 6 )) {

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("if :"); //Send the message
}
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.press(176); //the key to press (ASCII code)
}
Keyboard.releaseAll();

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.press(176); //the key to press (ASCII code)
}
Keyboard.releaseAll();

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.press(129); //the key to press (ASCII code)
}
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.press(179); //the key to press (ASCII code)
}
Keyboard.releaseAll();
delay( 1000 ); // waits a few milliseconds

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("else :"); //Send the message
}
Keyboard.releaseAll();
}
if (digitalRead( 7 )) {

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("while :"); //Send the message
}
Keyboard.releaseAll();
for (int i = 0 ; i < 2 ; ++i ) {

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.press(216); //the key to press (ASCII code)
}
Keyboard.releaseAll();
}
}
}

void C() { //customised function
if (digitalRead( 5 )) {

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("if () {}"); //Send the message
}
Keyboard.releaseAll();
for (int i = 0 ; i < 4 ; ++i ) {

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.press(216); //the key to press (ASCII code)
}
Keyboard.releaseAll();
}
}
if (digitalRead( 7 )) {

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("while () {}"); //Send the message
}
Keyboard.releaseAll();
for (int i = 0 ; i < 4 ; ++i ) {

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.press(216); //the key to press (ASCII code)
}
Keyboard.releaseAll();
}
}
if (digitalRead( 6 )) {

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("if () {}"); //Send the message
}
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.press(176); //the key to press (ASCII code)
}
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("else{}"); //Send the message
}
Keyboard.releaseAll();
}
}

Supplies

Arduino

Step 1: 左邊按鈕決定使用的語法

Python or C++

Step 2: 三個按鈕使用不同的函式

if or if else or while

Be the First to Share

    Recommendations

    • Metal Contest

      Metal Contest
    • Tinkercad Student Design Contest

      Tinkercad Student Design Contest
    • Micro:bit Contest

      Micro:bit Contest

    Comments