Elektor_Mag_-_January-February_2021

([email protected]) #1
lektor January & February 2021 35


  1. Click on Stop Simulation and then on Code (next to it on the
    left) to open a window that will allow you to enter source code. The
    ‘code view’ will slide in from the right-hand side and, initially, you
    will be presented with the Scratch editor. At the top you can change
    to Te x t (note: a warning will pop up, which you can dismiss).

  2. A small amount of ready-made code will appear in the win-
    dow. Delete all of this and replace it with the following commands.


const uint8_t iopin = A2;


void setup()
{
pinMode(iopin, INPUT);
Serial.begin(9600);
}


void loop()
{
Serial.println(digitalRead(iopin));
delay(10);
}



  1. When you next click on Start Simulation the program code
    will also be executed. If there are any syntax errors in your program
    they will be highlighted in the same way as in the Arduino IDE and
    must, of course, be fixed before continuing.
    13. In this example the Arduino will behave as a simple oscil-
    loscope, printing out the signal it sees on its input pin. This corre-
    sponds to the signal that is driving the piezo sounder. Click on the
    bottom of the code view window on Serial Monitor and you will be
    able to see the sequence of ones and zeros. In the far bottom right
    is a waveform icon. Click here to see a graphical representation of
    the signal.
    14. Turn the potentiometer and, as the sound changes, you will
    also see the displayed waveform change.


This article originally appeared in German in a special edition of
Elektor offering an introduction to electronics based upon the Arduino
platform. The English edition is now available: https://www.elektor.
com/elektor-special-introduction-to-electronics-with-arduino.
200225-C-04
Free download pdf