Module 4: Basics in Programming


Module 4: Basics in Programming

Goal of this Module: Understand the Basics of Programming and how to Convert Psuedocode Into Usable Code
Module 4: Basics in Programming Document Download

Module: Basics in Programming Lesson
Converting Pseudocode
  
 
code1

int lightPin = A0;  //define a pin for Photo resistor (input)
int ledPin = 13; // the pin for the led (output)


void setup()
{
    Serial.begin(9600);  //Begin serial communication
    pinMode( lightPin, INPUT );
    pinMode( ledPin, OUTPUT );
}
void loop()
{
    int lightValue = analogRead( lightPin );
    Serial.println( lightValue ); //Write the value of the photoresistor to the serial monitor.

    // if there is not enough light
    if ( lightValue < 400 ){
       // turn on the LED
       digitalWrite( ledPin, HIGH );
     }
    else{
       // otherwise, turn it off
       digitalWrite( ledPin, LOW );
      }
    delay(10); //short delay for faster response to light
}
Comments
  
code2

Variables
 
code3

Functions
 
code4

If Statements
 
code5

For Loops
 
code6