Alex Glow
Published

No Touchy

My first run with the Edison: an antisocial little project that just wants to be left alone.

Full instructions provided1,185

Things used in this project

Hardware components

Intel Edison with Arduino Breakout Kit
×1
Grove starter kit plus for Intel Edison
Seeed Grove starter kit plus for Intel Edison
We'll use the RGB LCD, buzzer, and touch sensor.
×1

Story

Read more

Code

Grove_TouchRGBuzz2.ino

C/C++
Final sketch
// Grove_Button + HelloWorld + Buzzer

#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;

const int colorR = 0;
const int colorG = 255;
const int colorB = 0;

const int pinButton = 3;                   // Touch sensor on D3
const int speakerPin = 4;                  // Buzzer on D4

int touchies = 0;

int length = 2; // the number of notes
char notes[] = "c "; // a space represents a rest
int beats[] = { 1, 7 };
int tempo = 300;

void playTone(int tone, int duration) {
    for (long i = 0; i < duration * 1000L; i += tone * 2) {
        digitalWrite(speakerPin, HIGH);
        delayMicroseconds(tone);
        digitalWrite(speakerPin, LOW);
        delayMicroseconds(tone);
    }
}

void playNote(char note, int duration) {
    char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
    int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

    // play the tone corresponding to the note name
    for (int i = 0; i < 8; i++) {
        if (names[i] == note) {
            playTone(tones[i], duration);
        }
    }
}

void setup()
{
    pinMode(pinButton, INPUT);                  // set button INPUT
    pinMode(speakerPin, OUTPUT);
    
    // set up the LCD's number of columns and rows:
    lcd.begin(16, 2);
    
    lcd.setRGB(colorR, colorG, colorB);
    lcd.print("touchy touchy");
    
    delay(1000);
}

void loop()
{
    if(digitalRead(pinButton))                     // when button is pressed
    {
        // set the cursor to column 0, line 1
        // (note: line 1 is the second row, since counting begins with 0):
        playTone(1519, 5);
        lcd.setRGB(255, 0, 0);
        touchies = touchies + 1;
        // Print a message to the LCD.
        lcd.setCursor(0, 1);
        // print the number of seconds since reset:
        lcd.print(touchies);
    }
    else
    {
      lcd.setRGB(colorR, colorG, colorB);
    }
    
    delay(100);
}

Credits

Alex Glow

Alex Glow

4 projects • 858 followers
The Hackster team's resident Hardware Nerd. I like robots, music, EEG, wearables, and languages. FIRST Robotics kid.

Comments

Add projectSign up / Login