Input ➤ Process ➤ Output

Input ➤ Process ➤ Output

With computers, everything is either an input that feeds info into the “brain” or an output that is controlled by the “brain”. The keyboard is an input, the monitor is an output. Can we say this is similar to our brains?

Prerequisite

None

Devices Input and Output

Just like computers, smart devices have inputs and outputs. Take a microwave oven for example, it takes user input from the keyboard and has a sensor to detect if the door is open. Those feed info into the processor inside. Depending on what buttons were pressed and the state of the door, the processor then controls the display, spinning the motor and heating device.

In & Out Methods

Functions reflect the Input -> Process -> Output concept. Some functions control things, like moving a robot, using Move(), others are input methods, like Sense().

Let’s assume the user wants to read button A. As you can imagine, a button is an input to the processor. And then we need to want to control the LED. The LED is an output from the processor.

Let us check if a button is pressed to flash the LED 3 times. Digital read and LED set functions will be detailed in future lessons.

Python

while(True):
  x=BrainPad.Digital.Read(BrainPad.Pin.ButtonA,0)
  if x==0:
    BrainPad.Led.Set(200,200,3)

C#

while(true){
  bool x=BrainPad.Digital.Read('a', BrainPad.Pin.PullUp);
  if (!x) {
    BrainPad.Led.Set(200,200,3);
  }
}

JS

while(true){
    let x = await BrainPad.Digital.Read(BrainPad.Pin.ButtonA, BrainPad.Pin.PullUp);
    if (!x) {
        await BrainPad.Led.Set(200,200,3);
    }
}

While you may think computers are smart and they just know when the button is pressed with the statement above, that is not entirely true. That statement checks the button one time and never again. Say we want to show the button state on the display/LEDs. We would have to repeatedly check the button and update the status in a loop. But how many times a second will we check the buttons?

What’s Next?

You can now start wiring the BrainPad to the physical world and experiment with available elements.


BrainStorm

The previous example used a loop that constantly checked for the button press and if the LED was pressed, it continued to blink the LED. Modern systems/languages use “Events”. An Even is usually a function that gets called when an event occurs. The internal operating system does its best to track that event. There are many ways to how hardware checks for the “event”. For example, a mobile phone is mostly asleep to conserve power. A tiny, and very low-power, circuit keeps an “eye” on the display in case it is touched. This generates an event to wake up the processor and activates the phone.

Content Licensing
Newsletter

Twitter Feed
Hot off the press!