Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1.  // Include application, user and local libraries
  2. #include "LCD_Launchpad.h"
  3.  
  4. LCD_LAUNCHPAD myLCD;
  5.  
  6. const int buttonPin1 = PUSH1;
  7. const int buttonPin2 = PUSH2;
  8. int buttonState1 = 0;  
  9. int buttonState2 = 0;
  10.  
  11. void setup() {
  12.   // initialize serial communications (for debugging only):
  13.   Serial.begin(9600);
  14.   myLCD.init();
  15.   pinMode(buttonPin1, INPUT_PULLUP);
  16.   pinMode(buttonPin2, INPUT_PULLUP);
  17. }
  18.  
  19. void loop() {
  20.   // read the sensor:
  21.   int sensorReading = analogRead(A9);
  22.   // print the sensor reading so you know its range
  23.   Serial.println(sensorReading);
  24.   // map the pitch to the range of the analog input.
  25.   // change the minimum and maximum input numbers below
  26.   // depending on the range your sensor's giving:
  27.   int thisPitch = map(sensorReading, 20, 10000, 80, 11000);
  28.  
  29.   // play the pitch:
  30.   tone(9, thisPitch);
  31.  
  32.   myLCD.clear();
  33.   myLCD.showSymbol(LCD_SEG_RADIO, 1);
  34.   myLCD.println(thisPitch + 2);
  35.   myLCD.print("Hz ");
  36.  
  37.   buttonState1 = digitalRead(buttonPin1);
  38.     if (buttonState1 == LOW) {    
  39.     // turn delay on:    
  40.     delay(50);
  41.     }
  42.    buttonState2 = digitalRead(buttonPin2);
  43.     if (buttonState2 == LOW) {    
  44.     // turn delay on:    
  45.     delay(200);
  46.   }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement