Combination Lock – Week Three Homework

Combination Lock from Sarah Page on Vimeo.

The LCD screen will remain “LOCKED” until you flex the flex sensor (so it is either lower than 700 or higher than 800 – flexing it either direction will work) and hold down the button. Then you will get an exciting “Unlocked!” scrolling message.

code below:
//AWESOME LOCK!

// include the library code:
#include LiquidCrystal.h

// initialize the library with the numbers of the pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int buttonPin = 13;

//flex sensor in A1
const int flexpin = 1;

//button on/off
int buttonState = 0;

void setup() {

// set up the LCD’s number of columns and rows:
lcd.begin(16,2);
pinMode(6, OUTPUT);
pinMode(buttonPin, INPUT);
//lcd.print(“LOCKED!”);
}

void loop() {
int flexposition; // Input value from the analog pin.
// Read the position of the flex sensor
flexposition = analogRead(flexpin);
Serial.print(“sensor: “);
Serial.println(flexposition);

//button
buttonState = digitalRead(buttonPin);

//LCD SCREEN
// set the cursor on LCD to (0,0):
lcd.setCursor(0, 0);

// establish the brightness (in place of the potentiometer)
analogWrite(6, 100);

//is the button pressed? and is the flexer flexed!?
if((buttonState == HIGH) && ((flexposition > 799) || (flexposition < 699))) {
// for loop to print the characters in the array
lcd.clear();
for (int thisChar = 0; thisChar < 9; thisChar++) {
char m[] = “Unlocked!”;
lcd.print(m[thisChar]);
//speed of the characters showing on the LCD
delay(100);
}
} else {
lcd.print(“LOCKED!”);
delay(50);
}

// turn off automatic scrolling
lcd.noAutoscroll();

// clear screen for the next loop:
lcd.clear();
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s