Question

Develop a simple code to read a digital pin in the GPIO set of pins in...

Develop a simple code to read a digital pin in the GPIO set of pins in your micro-controller and set another digital pin to output high, if the read pin is also high.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

int a=11;
int b=7;
int v=0;
void setup() {
pinMode(a,INPUT);
pinMode(b,OUTPUT);
Serial.begin(9600);

}

void loop() {
int v=digitalRead(a);// Reads digital pin 'a' i.e 11
  
if(v==1)
{
digitalWrite(b,HIGH);}
else if(v==0)
{
digitalWrite(b,LOW);
//delay(1000);
}

}

Add a comment
Know the answer?
Add Answer to:
Develop a simple code to read a digital pin in the GPIO set of pins in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2. Given the following setup for GPIO (fill in all the blanks, refer to pages 1-4)...

    2. Given the following setup for GPIO (fill in all the blanks, refer to pages 1-4) GPIOB_MODER 0x10000 //GPIOB_OTYPER is not needed as its default value is zero GPIOB_OSPEEDRI=0x3000; GPIOBPUPDRI= 0x80; - a. Which port is being initialized? Port b. Describe the important features from the initialization for pin 3 Ifor example input, output, alternate function, analog, pull up, pull down, push/pull, open drain out, speed, etc.). Px3 is initialized to be c. Which pin is being initialized as an...

  • INTRODUCTION TO MICRO CONTROLLERS Question:- Using 3 digital pins as binary bits, the user should have...

    INTRODUCTION TO MICRO CONTROLLERS Question:- Using 3 digital pins as binary bits, the user should have the ability to select a number, using a "1" from your 5 volt source and a "0" from a ground point, any number (base 10) between 0 and 7. The user will select the number by inputting the equivalent binary number into the digital pins. That being said, your objective is to output the number (in base 10) to a serial display. ALL IS...

  • 6.3.7. Analog write and digital write methods Do this Similar to the ar and dr methods, write the methods aw and dw. Each of these methods has a pin number parameter and a value parameter. Write the...

    6.3.7. Analog write and digital write methods Do this Similar to the ar and dr methods, write the methods aw and dw. Each of these methods has a pin number parameter and a value parameter. Write the value to the corresponding analog or digital pin instance. Just like ar and dr, write the value to the pin only if the pin number is in the correct 17 range. These functions do not need to retum anything. One other thing: in...

  • Code the following example and screenshot the text output. After you have the test code working,...

    Code the following example and screenshot the text output. After you have the test code working, modify it so that it has the following features: ○ The ‘while’ loop is inside a try/except error check. This allows a <CTRL>C to break out of the loop ○ Keep track of the number of button presses with an accumulator variable ○ After the loop is ended with an exception, create an attractive output which tells the user that the program has ended...

  • CODE IN C++ THANK YOU Write a program that simulates a microprocessor with eight pins Each...

    CODE IN C++ THANK YOU Write a program that simulates a microprocessor with eight pins Each pin is of enumerated type and serves a device from the set ground, power, usb, available, camera, audio, keyboard, monitor When a signal is set on a pin, it serves the connected devices by turning it on. Simulate real life pin interrupts in an operating system using a random number generator and a forever loop Your output must look like this: ervicing KEYBOARD ervicing...

  • Question 3: In class we showed how to simply light up an LED on our Teensy...

    Question 3: In class we showed how to simply light up an LED on our Teensy microcontroller. In fact, the procedure is similar for all processors including a simpler 8-bit ATmega 328P (a.k.a Arduino Uno) For purposes of this exercise, let's say that the ATmega328 has 4 regular GPIO ports; A, B, C, and D, each with 8 pins. Every GPIO port has three registers (outlined in table below) PORTX: used to write output on a pin on port X...

  • The following code implements some Pulse Width Modulation (PWM) code and interacts with a Curiosity board (usual connections of pushbutton on portC pin4 (logic 0 when pressed), LEDs on portA pins 1,...

    The following code implements some Pulse Width Modulation (PWM) code and interacts with a Curiosity board (usual connections of pushbutton on portC pin4 (logic 0 when pressed), LEDs on portA pins 1, 2 and 5, and portC pin 5, and Potentiometer on portC pin 0 - not all used here). Note the following relationship for the duty cycle 96DutyCycle DutyCycleNumber The Duty cycle (as a percentage of 100) is set by 80 100 PWM_init); // initialisation of PWM module 1...

  • Draw the flow chart of this C code program? /old state flag bit oldstate; void main...

    Draw the flow chart of this C code program? /old state flag bit oldstate; void main ( //configure PORTC pins 1/configure PORTA pins as digital digital ANSELC-0; as ANSELA 0; TRISAO bit = 1 ; //set RAO pin as input 1/ configure PORTC as Output TRISC-0X00; LATC 0XFF; //Initial PORTC value oldstate 0; while (1) if (Button (&PORTA, 0, 1, 1)) { //Detect Logical one oldstate-1; //Endless 1oop T/Update flag if (oldstate && Button (&PORTA, 0, 1, 0)) LATC LATC;...

  • Write code to make pin A0 (Analog 0) on the NodeMCU an input, and read its...

    Write code to make pin A0 (Analog 0) on the NodeMCU an input, and read its voltage into currentVoltage (declare this as a double). Put your code inside setup(), below. Do not use loop(). void setup(){         }

  • Need help in filling the missing lines in the program template provided down below. (Arduino Uno)....

    Need help in filling the missing lines in the program template provided down below. (Arduino Uno). Using the program template provided, fill in the missing lines in the program which increments an unsigned integer variable when the “pin 2” button is pressed and decrements an unsigned integer variable when the “pin 3” button is pressed. Your program must display the integer variable (modulo 8) on the 7-segment LED display you designed in the previous lab. Once again you should be...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT