Posts

Showing posts from September, 2021

Coursera assignment 3

Coursera assignment 3 import time import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) ledPin = 11 buttonPin = 13 GPIO.setup(ledPin, GPIO.OUT) GPIO.setup(buttonPin, GPIO.IN, pull_up_down = GPIO.PUD_UP) try: while True: if( GPIO.input(buttonPin) ): GPIO.output(ledPin, GPIO.HIGH) else: GPIO.output(ledPin, GPIO.HIGH) time.sleep(0.25) GPIO.output(ledPin, GPIO.LOW) time.sleep(0.25) finally: GPIO.output(ledPin, GPIO.LOW) GPIO.cleanup() print("\nStopped") exit()

Coursera assignment 2

Coursera assignment 2 int ledPin = 10; int photoResistorPin = A0; int maxValue = 0; int minValue = 1023; int sensorReading; int sensorValue; int ledValue; void setup() { pinMode(ledPin, OUTPUT); digitalWrite(ledPin, HIGH); long startTime = millis(); long endTime = millis(); while( (endTime - startTime) maxValue) maxValue = sensorReading; endTime = millis(); } digitalWrite(ledPin, LOW); } void loop() { sensorReading = analogRead(photoResistorPin); sensorValue = constrain(sensorReading, minValue, maxValue); ledValue = map(sensorValue, minValue, maxValue, 255, 0); analogWrite(ledPin, ledValue); }

Coursera Assignment 1

Coursera Assignment 1 I have build a circuit which has two pushButtons connected to the pins redButtonPin and yellowButtonPin . And a led connected to the pin ledPin . When the any of the button is pressed the led will turn on. You can see the code below :- int ledPin = 7; int redButtonPin = 11; int yellowButtonPin = 9; int redButtonReading = 0; int yellowButtonReading = 0; void setup() { pinMode(ledPin, OUTPUT); pinMode(redButtonPin, INPUT); pinMode(yellowButtonPin, INPUT); } void loop() { redButtonReading = digitalRead(redButtonPin); yellowButtonReading = digitalRead(yellowButtonPin); if( redButtonReading == HIGH || yellowButtonReading == HIGH ) digitalWrite(ledPin, HIGH); else digitalWrite(ledPin, LOW); }