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:

// 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:
pinMode(6, OUTPUT);
pinMode(buttonPin, INPUT);

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

buttonState = digitalRead(buttonPin);

// 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
for (int thisChar = 0; thisChar < 9; thisChar++) {
char m[] = “Unlocked!”;
//speed of the characters showing on the LCD
} else {

// turn off automatic scrolling

// clear screen for the next loop:


Leave a Reply

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

You are commenting using your 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