-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question in regards of how does portConfig works #109
Comments
Hi Sharvin, Nice to meet you! In general, each port has up to 8 pins (most of them have 8). For Arduino Uno, the mapping is as follows:
So if you wanted to listen for Arduino's pin 8, that'd correspond to pin number 0 (the first pin) on Port B, and the code would look something like: const portB = new AVRIOPort(cpu, portBConfig);
portB.addListener(() => {
const turnOn = port.pinState(0) === PinState.High;
setLedState(turnOn);
}); For Arduino mega, it's a similar concept, and I see that you have already found the mapping. Here's an example how to read these lines:
The first part of the comment is the port name (G) and pin index in the port (2), and the second part is the Mega pin number. So what this line says: Mega pin 39 is pin 2 on Port G. So you would listen it using something like: const portG = new AVRIOPort(cpu, portGConfig);
portG.addListener(() => {
const turnOn = port.pinState(2) === PinState.High;
setLedState(turnOn);
}); I hope this is helpful! |
Hey Urish, thank you for the response and help. I went through your suggestion and update the code as follows:
I also updated the port config as follows:
Now when I run the code led doesn't turn on so I console logged and I got the following observation: value of Also it doesn't attach the listener thus the function inside listerner doesn't occur. I don't know what am I doing wrong or missing here. Any help is appreciate. Following is the link for sanbox code updated. |
Hi Sharvin,
I'm on vacation today, I'll have a look when i get back and update here
…On Sun, Oct 10, 2021, 12:00 PM Sharvin Shah ***@***.***> wrote:
Hey Urish,
thank you for the response and help.
I went through your suggestion and update the code as follows:
const arduinoCode = `
void setup() {
// put your setup code here, to run once:
pinMode(39, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(39, HIGH);
delay(1000);
digitalWrite(39, LOW);
delay(1000);
}`;
I also updated the port config as follows:
const port = new AVRIOPort(cpu, portGConfig);
port.addListener(() => {
const turnOn = port.pinState(2) === PinState.High;
setLedState(turnOn);
console.log("LED", turnOn);
});
Now when I run the code led doesn't turn on so I console logged and I got
the following observation:
value of port.pinState(2) is 2 and value of PinState.High is 1.
Also it doesn't attach the listener thus the function inside listerner
doesn't occur.
I don't know what am I doing wrong or missing here. Any help is appreciate.
Following is the link
<https://codesandbox.io/s/nice-forest-8i5h7?file=/src/App.js> for sanbox
code updated.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#109 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAGZ3HXKRNVC6OCK72CI3YLUGFIZ5ANCNFSM5FCNJP5Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Sure thanks |
So for the mega:
You can find a complete example (somewhat complex, but functional) here: https://stackblitz.com/edit/avr8js-mega-ws2812?file=execute.ts |
Hey @urish thank you for solving the doubt. Much appreciated the help. |
Hello,
First of all, thank you for developing such a great library.
I completed this video tutorial that I found in the readme of this project.
Now when I tried changing the port from
portDConfig
toportBConfig
or something else, the LED stopped working.Working:
Not Working:
I also tried changing the pin both in code and this code snippet below:
Working:
Not Working:
What I observed was it worked for 0 to 7 but stopped working for numbers bigger than 7.
I made sure the number here and in arduino code are same.
I was going through the issues of this project to understand what I was doing wrong and I found a discussion where the author of this repo has commented.
But I still didn't understood how this is working.
I am more confused when various arduino boards are brought in.
For example:
Arduino Mega has 0 to 53 Digital GPIO Pins. So now to determine port for each pin number I went to the arduino code
https://github.com/arduino/ArduinoCore-avr/blob/60f0d0b125e06dbf57b800192c80e5f60d681438/variants/mega/pins_arduino.h#L162
Thanks to above mentioned github discussion I found this.
Now I am wondering why other portConfig are not working except
portDConfig
and why only range 0 to 7 is working.This is the sandbox link attached here.
Any help in this matter would be appreciated as I am much of beginner in electronics and trying to understand how everything is combining together for educational purpose.
The text was updated successfully, but these errors were encountered: