Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <AFMotor.h>
- AF_Stepper motorL(200, 1); // Left Motor, M1 & M2
- AF_Stepper motorR(200, 2); // Right Motor, M3 & M4
- // Forward is Up on both motors.
- // button holds the sketch in setup, until pressed. This stops the
- // motors from moving under USB power while uploading.
- const int button = 2;
- const int LED = 14; // LED indicates end of sketch
- int progress = 0; // iteration/cycle
- // uses the "progress" to look into the array, and present the switch
- // progress, so it knows what basic to do.
- int current = 0;
- const int pixelsteps = 32; // size of a pixel, in steps
- //pixelsteps needs to be 2,4,6,8,16,32,or 64 else will skew image...
- // this basic and format works
- // dont fiddle with it!
- int basic[]{
- 5,5,7,3,
- 5,4,4,5,7,5,
- 5,4,3,3,4,5,7,7,
- 5,4,3,2,2,3,4,5,7,9,
- 5,4,3,2,1,1,2,3,4,5,7,11,
- 5,4,3,2,1,1,1,1,2,3,4,5,7,13,
- 5,4,3,2,1,1,1,1,1,1,2,3,4,5,7,15,
- 5,4,3,2,1,1,1,1,1,1,1,1,1,3,4,5,7,17,
- 5,4,3,2,1,1,1,1,1,1,1,1,1,1,2,3,4,5,7,19,
- 5,4,3,2,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,7,21,
- 5,4,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,7,23,
- 5,4,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,7,25,
- 5,4,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,7,27,
- 5,4,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,7,29,
- 5,4,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,7,31,
- 5,4,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,7,31,
- 5,4,3,2,1,1,1,1,1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,4,5,7,27,
- 5,4,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,7,25,
- 5,4,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,7,23,
- 5,4,3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,7,21,
- 5,4,3,2,1,1,1,1,1,1,1,1,1,1,1,1,2,3,4,5,7,19,
- 5,4,3,2,1,1,1,1,1,1,1,1,1,1,2,3,4,5,7,17,
- 5,4,3,2,1,1,1,1,1,1,1,1,2,3,4,5,7,15,
- 8
- };// end of basic
- /* Comma separate pixels or instructions: 1 is none, 2 is lightest,
- * 6 is Darkest.
- 7 is return while the number following any 7 is the distance to return
- * in pixels,
- 8 is End. pixels are currently squares of 40 steps
- **********************************************************************/
- void setup() {
- pinMode (LED, OUTPUT);
- pinMode (button, INPUT);
- motorL.setSpeed(50); // 10 rpm
- motorR.setSpeed(50); // 10 rpm
- //hold
- while (digitalRead (button) == HIGH){
- // stops script. Its waiting for a button press (LOW on "button")
- }
- }
- void loop() {
- current = basic[progress]; // ****************************************
- switch (current) {
- case 1: // nil, straight to next pixel
- motorL.step(pixelsteps , FORWARD, INTERLEAVE);
- break;
- case 2: // lightest, 1 step
- pixel(2);
- break;
- case 3: // light, 2 steps
- pixel(4);
- break;
- case 4: // Medium, 4 steps
- pixel(8);
- break;
- case 5: // Darker, 10 steps
- pixel(16);
- break;
- case 6: // Darkest 20 steps
- pixel(32);
- break;
- case 7: // Carriage Return.
- motorR.step((pixelsteps +1), FORWARD, INTERLEAVE);
- ++progress;
- current = basic[progress]; // **************************************
- //The number following any 7 in the array is used only to tell it
- // how far to return,
- motorL.step((current * pixelsteps), BACKWARD, INTERLEAVE);
- //and is then discarded. It is not a case, nor a shade.
- motorR.step(1, FORWARD, INTERLEAVE);
- break;
- // Lights the LED and waits for a button press as a method of stop
- case 8:
- digitalWrite (LED, HIGH);
- //hold
- while (digitalRead (button) == HIGH){
- // stops script. Its waiting for a button press (LOW on "button")
- }
- break;
- }
- ++progress; // move to the next instruction in the array!
- }
- void pixel(int shade) {
- for (int i = 0; i < (shade / 2); ++i) {
- motorL.step((pixelsteps / shade), FORWARD, INTERLEAVE);
- motorR.step((pixelsteps - 2), FORWARD, INTERLEAVE);
- motorL.step((pixelsteps / shade), FORWARD, INTERLEAVE);
- motorR.step((pixelsteps - 2), BACKWARD, INTERLEAVE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement