Furthermore I propose you study the tutorial
especially the example 4 shows you how you can gather a number from serial. Use that concept in your sketch!