Question

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

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

        def __init__(self):
                self._numDigitals = 14
                self._numAnalogs = 6
                self._digitals = [Digital() for _ in range(self._numDigitals)]
                self._analogs = [Analog() for _ in range(self._numAnalogs)]

        
        def ar(self, pin):
                if pin >= 0 and pin < self._numAnalogs:
                        return self._analogs[pin].read()

        def dr(self, pin):
                if pin >= 0 and pin < self._numDigitals:
                        return self._digitals[pin].read()
        
        def aw(self, pin, value):
                if pin >= 0 and pin < self._numAnalogs:
                        print('LED is ' + ('ON' if value == 1 else 'OFF'))
                        self._analogs[pin].write(value)

        def dw(self, pin, value):
                if pin >= 0 and pin < self._numDigitals:
                        print('LED is ' + ('ON' if value == 1 else 'OFF'))
                        self._digitals[pin].write(value)

        def dm(self, pin, mode):
                if pin >= 0 and pin < self._numDigitals:
                        self._digitals[pin].set_mode(mode)
Add a comment
Know the answer?
Add Answer to:
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...
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
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
ADVERTISEMENT