用户工具

站点工具


en:learing:examples:main

Examples

See the following examples for an overview of the Ocrobot Core functions and Libraries

Core Functions

Simple programs that demonstrate basic Ocrobot commands. These are included with the Ocrobot environment; to open them, click the Open button on the toolbar and look in the examples folder.

1.Basics

  • BareMinimum: The bare minimum of code needed to start an Ocrobot sketch.
  • Blink: Turn an LED on and off.
  • DigitalReadSerial: Read a switch, print the state out to the Ocrobot Serial Monitor.
  • AnalogReadSerial: Read a potentiometer, print its state out to the Ocrobot Serial Monitor.
  • Fade: Demonstrates the use of analog output to fade an LED.
  • ReadAnalogVoltage : Reads an analog input and prints the voltage to the serial monitor

2.Digital

  • Blink Without Delay: blinking an LED without using the delay() function.
  • Button: use a pushbutton to control an LED.
  • Debounce: read a pushbutton, filtering noise.
  • Button State Change: counting the number of button pushes.
  • Input Pullup Serial: Demonstrates the use of INPUT_PULLUP with pinMode().
  • Tone: play a melody with a Piezo speaker.
  • Pitch follower: play a pitch on a piezo speaker depending on an analog input.
  • Simple Keyboard: a three-key musical keyboard using force sensors and a piezo speaker.
  • Tone4: play tones on multiple speakers sequentially using the tone() command.

3.Analog

  • AnalogInOutSerial: Read an analog input pin, map the result, and then use that data to dim or brighten an LED.
  • Analog Input: Use a potentiometer to control the blinking of an LED.
  • AnalogWriteMega: Fade 12 LEDs on and off, one by one, using an Ocrobot Mega board.
  • Calibration: Define a maximum and minimum for expected analog sensor values.
  • Fading: Use an analog output (PWM pin) to fade an LED.
  • Smoothing: Smooth multiple readings of an analog input.

4.Communication

These examples include code that allows the Ocrobot to talk to Processing sketches running on the computer. For more information or to download Processing, see processing.org. There are also Max/MSP patches that can communicate with each Ocrobot sketch as well. For more on Max/MSP see Cycling 74. For Pd patches that can communicate with these sketches, see Scott Fitzgerald's examples.

  • ReadASCIIString: Parse a comma-separated string of ints to fade an LED.
  • ASCII Table: Demonstrates Ocrobot's advanced serial output functions.
  • Dimmer: Move the mouse to change the brightness of an LED.
  • Graph: Send data to the computer and graph it in Processing.
  • Physical Pixel: Turn a LED on and off by sending data to your Ocrobot from Processing or Max/MSP.
  • Virtual Color Mixer: Send multiple variables from Ocrobot to your computer and read them in Processing or Max/MSP.
  • Serial Call Response: Send multiple variables using a call-and-response (handshaking) method.
  • Serial Call Response ASCII: Send multiple variables using a call-and-response (handshaking) method, and ASCII-encode the values before sending.
  • SerialEvent: Demonstrates the use of SerialEvent().
  • Serial input (Switch (case) Statement): How to take different actions based on characters received by the serial port.
  • MIDI: Send MIDI note messages serially.

5.Control Structures

  • If Statement (Conditional): How to use an if statement to change output conditions based on changing input conditions.
  • For Loop: Controlling multiple LEDs with a for loop and.
  • Array: A variation on the For Loop example that demonstrates how to use an array.
  • While Loop: How to use a while loop to calibrate a sensor while a button is being read.
  • Switch Case: How to choose between a discrete number of values. Equivalent to multiple If statements. This example shows how to divide a sensor's range into a set of four bands and to take four different actions depending on which band the result is in.
  • Switch Case 2: A second switch-case example, showing how to take different actions based in characters received in the serial port.

6.Sensors

  • ADXL3xx: Read an ADXL3xx accelerometer.
  • Knock: Detect knocks with a piezo element.
  • Memsic2125 : Two-axis acceleromoter.
  • Ping: Detecting objects with an ultrasonic range finder.

7.Display

  • Examples of basic display control
  • LED Bar Graph: How to make an LED bar graph.
  • Row Column Scanning: How to control an 8×8 matrix of LEDs.

8. strings

en/learing/examples/main.txt · 最后更改: 2023/06/07 04:23 由 127.0.0.1