DigitalRead & Serial.println Questions

doaway:
Thanks alot!!!!

There do have a ENb and RWb in my code, I use pwm to generate square wave.
I also face a problem, when I perform digitalRead(pin), I do not know when and where the data is read. I only want to read the data when RWb = 1 (risingedge) and ENb = 0. And only want to read it once because the rest data is same.
Otherwise the data I read is void (maybe wrong data). so my code is

You are welcome!

But you started off with one problem and now we are looking at something else. And from what I am reading you/we need to understand how your memory circuit connected to your Mega works. The PWM usage is very strange.

I recommend you (and others) when requesting help to:

  1. Post the problem with example code.
  2. Add some schematic/circuit if you are connecting to hardware.
  3. And try to be clear on the problem that you want help with.
    Otherwise there is a high risk that people back off from trying to help out. By extending with a new problem it becomes difficult for others to reuse any solution that is presented as the title becomes more and more irrelevant to the contents of the posting. If you change the contents I recommend a new posting. Solve one problem - go forward - reuse solutions!

So please tell us about the schematics of your hardware and how you think the your code works.

For now I think we have fixed your initial problem: Read multiple pins to create an integer value.

Cheers!