Examples - Sensorboard - Piezo
Piezo
This Example shows the use of a Piezo Sensor.
/************************************************************************************************** * * Piezo Sensor * * Version: 1.0.0 - November 2008 * Author: Etienne Ribeiro / tutorial assistant caad / eribeiro[at]ethz.ch * Supervisor: Christoph Wartmann / chair for caad - ETH Zürich / wartmann[at].arch.ethz.ch * * Desc: Shows the use of a Piezo Sensor on analog pin. * ***************************************************************************************************/ // Const static int pinAnalogIn = 0; static int pinInMaxValue = 1000; static int pinOut[] = {0, 1, 2, 3, 4}; static int pinOutCount = 5; static boolean enableSerial = true; // Setup void setup() { // LED (2 * blink) pinMode(48, OUTPUT); digitalWrite(48, HIGH); delay(200); digitalWrite(48, LOW); delay(200); digitalWrite(48, HIGH); // Serial (Print to serial if enableSerial = true) if (enableSerial == true) Serial.begin(9600); // pinMode for (int iPin = 0;iPin < pinOutCount;iPin++) { pinMode (pinOut[iPin], OUTPUT); } } void loop() { // Read: int val = analogRead(pinAnalogIn); // LED on/off: for (int iPin = 0;iPin < pinOutCount;iPin++) { if (pinInMaxValue / pinOutCount * (iPin + 1) > val) digitalWrite(pinOut[iPin], HIGH); else digitalWrite(pinOut[iPin], LOW); } // Debug if (enableSerial == true) { Serial.print(" Val: "); Serial.print(val, DEC); Serial.print(" (Pin "); Serial.print(pinAnalogIn, DEC); Serial.print(") "); Serial.println(""); } // Wait: delay(50); }